random产生的随机数会产生重复,怎么解决 啊 ?
解决方案 »
- 求指教:eclipse中debug
- delAction如何得到传过来的哦a href=del.do?username=bean.getName()>"。
- 在JTextField中怎么 显示当前系统时间呢 ?有什么函数?
- IK_CAnalyzer的一个问题
- 高手!高手!
- 求JDK6.0 API 走过路过都来down一个
- 请教图形界面编程的问题
- 请问BAS4.5的序列号
- FlowLayout()是什么意思
- 关于 if(true) 与 Unreachable code
- 线程问题! 结果另我很困惑,望高手指点!
- FileRead,FileinputStream和RandomAccessFile有什么区别
public class Arrey
{
public static void main(String args[])
{
int arry[];
char a[];
a=new char[10];
arry=new int[10];
for(int i=0;i<10;i++)
{
arry[i]=(int)(Math.random()*27+97);
a[i]=(char)arry[i];
System.out.println(a[i]);
}}}或则import java.lang.Math.*;
public class Arrey
{
public static void main(String args[])
{
char arry[];
int a[];
a=new int[10];
arry=new char[10];
for(int i=0;i<10;i++)
{
arry[i]=(char)('a'+(Math.random()*26));
System.out.print(arry[i]+" ");
a[i]=(int)arry[i];
}}}
int random;
int len=c.length();
for(int i=0;i <10;i++){
random=(int)Math.random()*len;
arry[i]=c[random];
c[random]=c[len-1];
c[len-1]=arry[i]
len--;
}
第二次,size已经变小了。如果需要重新从A-Z取,需要重新初始化一个List
-----------------------------------------------
Random r=new Random(System.currentTimeMillis());
public static void main(String[]args){
int array[];
char a[];
array=new int[10];
a=new char[10];
for(int i=0;i<10;i++){
array[i]=(int)(Math.random()*26+97);
int j=0;
while(j<i){
if(array[i]==array[j]){
array[i]=(int)(Math.random()*26+97);
j=-1;
}
j++;
}
a[i]=(char)array[i];
}
for(int i=0;i<10;i++){
System.out.print((a[i])+" ");
}
}
}
//方法二:取出的字母与数组最后面的字母交换位置,之后统一取出
public class random{
public static void main(String[]args){
System.out.println((char)(97));
char[]temp=new char[26];
char[]result=new char[10];
//给temp字符数组赋初值
for(int i=0;i<26;i++){
temp[i]=(char)(97+i);
}
for(int i=0;i<10;i++){
char j;
int number=(int)(Math.random()*(25-i));
j=temp[number];
temp[number]=temp[25-i];
temp[25-i]=j;
result[i]=j;
}
for(int i=0;i<10;i++){
System.out.print(result[i]+" ");
}
}
}
很简单
List<Character> list = new ArrayList<Character>();
String zimu = "ABCDEFGHIJKLMNOPQRSTUVWSYZ";
//把26个字符放到一个list中
for(int i=0;i<zimu.length();i++){
list.add(new Character(zimu.charAt(i)));
}
//打乱
Collections.shuffle(list);
//输出10个
for(int i=0;i<10;i++){
System.out.println(list.get(i));
}
详细参看我的blog
http://blog.csdn.net/zrzlj/archive/2008/04/03/2248492.aspx呵呵,帮我踩踩