posts - 495,comments - 227,trackbacks - 0
import java.util.Arrays;
import java.util.Random;

/**
 * 其实思路很简单,就是从seed数组中取出还未选中的种子

 
*/
public class RandomTest {

    
public static void main(String[] args) {
        
// 声明一个种子
        int seed[] = { 123456789 };
        
// 存放生成后的数字
        int[] destArray = new int[seed.length];
        
// 声明一个Random实例
        Random random = new Random();
        
// 循环种子
        for (int i = 0; i < seed.length; i++) {
            
// 随机得到种子中的一个位置
            int j = random.nextInt(seed.length - i);
            
// 把该位置上的种子输出
            destArray[i] = seed[j];
            
// 把种子中末尾的种子替换得到的种子
            seed[j] = seed[seed.length - 1 - i];
        }
        System.out.println(Arrays.toString(destArray));
    }

}
posted on 2011-09-14 16:10 SIMONE 阅读(779) 评论(0)  编辑  收藏 所属分类: JAVA

只有注册用户登录后才能发表评论。


网站导航: