Topic: 请问一下有产生不重复随机数的函数吗? |
Print this page |
1.请问一下有产生不重复随机数的函数吗? | Copy to clipboard |
Posted by: albertwoo Posted on: 2004-10-12 18:55 各位大虾: 请问一下有产生不重复随机数的函数吗? 我知道vb,vc++里面都有,但我在jsdk文档里找不到~~ 我自己写的又不太理想,所以想请各位指教一下~ 谢谢! |
2.Re:请问一下有产生不重复随机数的函数吗? [Re: albertwoo] | Copy to clipboard |
Posted by: cjyzpcl Posted on: 2004-10-12 19:34 Math.random(),产生0-1之间的随机数。 |
3.Re:请问一下有产生不重复随机数的函数吗? [Re: albertwoo] | Copy to clipboard |
Posted by: albertwoo Posted on: 2004-10-13 14:40 我知道啊,但是能保证他不重复吗? 谢谢 |
4.Re:请问一下有产生不重复随机数的函数吗? [Re: albertwoo] | Copy to clipboard |
Posted by: ljy0000 Posted on: 2004-10-13 15:13 java.util.Random类可以。 |
5.Re:请问一下有产生不重复随机数的函数吗? [Re: albertwoo] | Copy to clipboard |
Posted by: kavinwang Posted on: 2004-10-14 16:34 不重复那还叫随机数吗?随机数不保证不重复呀! |
6.Re:请问一下有产生不重复随机数的函数吗? [Re: albertwoo] | Copy to clipboard |
Posted by: caleb Posted on: 2004-10-14 18:46 True random number does not exist, at least it does not exist at this moment of time .. .. I guess that You are refering to UUID in VB or VC, you may update to SDK5.0, which support UUID. |
7.noSame [Re: albertwoo] | Copy to clipboard |
Posted by: battlekiller Posted on: 2004-10-17 19:44 用我的这个方法适宜市,但要有长度,再你声名的这段长度内不会有重复 他产生一个数组 public void noSame(int number,int length) { double array[]=new int[length]; int accept=0; do{ to: double a=Math.random()*number; array[accept]=a; accept++; if(accept==1) {continue;} else{ for(int counter=0;counter<=accept;counter++) { for(int n=1;n<=accept;n++) {if(array[counter]==array[n]) { if(counter==n) {n++; break;} accept--; continue to; } } } } }while(accept==length); } 调用事实看 |
8.11 [Re: albertwoo] | Copy to clipboard |
Posted by: battlekiller Posted on: 2004-10-17 19:45 有问题联系我 QQ312161799 我是在网吧编的,难免有错,望谅解 |
9.Re:请问一下有产生不重复随机数的函数吗? [Re: albertwoo] | Copy to clipboard |
Posted by: yongl04 Posted on: 2004-10-25 21:05 import java.util.Vector; class ToGetNoSameRandom{ Vector vetAarry = new Vector(); public ToGetNoSameRandom(int getNumber){//要产生的随即数数量 if(getNumber < 0) getNumber = 0; Integer tempInt = new Integer(0); for(int i = 0 ;i < getNumber;i++){ tempInt = new Integer((int)(Math.random()*100)); if(vetAarry.indexOf(tempInt) == -1) vetAarry.addElement(tempInt); } } public void pintTheRandoms(){ for(int i = 0;i < vetAarry.size();i++ ){ System.out.println(vetAarry.elementAt); } } public static void main(String[] args){ new ToGetNoSameRandom(20).pintTheRandoms(); } } 我的试试看。 |
10.Re:请问一下有产生不重复随机数的函数吗? [Re: albertwoo] | Copy to clipboard |
Posted by: kavinwang Posted on: 2004-10-25 21:25 连续取100000次,就傻了。 |
11.Re:请问一下有产生不重复随机数的函数吗? [Re: albertwoo] | Copy to clipboard |
Posted by: littledeer1974 Posted on: 2004-10-25 23:20 也许你已经看到了,这里有比较详细的说明 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |