?? myrand.java
字號:
/*
* MyRand.java
*
* Created on 2007年11月17日, 上午5:06
*
*/
package myUtil;
import java.util.*;
/**
* some customed random methord.
* @author yuhui_bear
*/
public class MyRand {
private ArrayList<NumberBox> st;
/**
* Creates a new instance of MyRand
*/
public MyRand(int formin) {
st = new ArrayList();
for ( int i= 0 ; i< formin;i++){
st.add(new NumberBox(i));
}
}
/**
* generate a group of length n from range from.
* @param n ,length of the choosing group.
* @return the new random sequence.
*/
public int[] randSequence(int n){
Random myrand = new Random();
ArrayList<NumberBox> tlist = (ArrayList<NumberBox>)st.clone();
int[] temp = new int[n];
int t=0;
for ( int k = 0 ; k < n; k++){
t= myrand.nextInt(tlist.size());
temp[k] =tlist.get(t).intData;
tlist.remove(t);
}
return temp;
}
/**
* generate a group of length n from range from.
* @param n ,length of the choosing group.
* @param from , number range to choose.
* @return the new random sequence.
*/
public static int[] randSequence(int n , int from){
Random myrand = new Random();
int[] temp = new int[n];
ArrayList<NumberBox> st = new ArrayList();
int t=0;
for ( int i= 0 ; i< from;i++){
st.add(new NumberBox(i));
}
for ( int k = 0 ; k < n; k++){
t= myrand.nextInt(st.size());
temp[k] =st.get(t).intData;
st.remove(t);
}
return temp;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -