也就是说 有一个函数 给该函数中放入一个INT的数字例如 50
接着在这里方法内获取当前系统日期 然后来对0-50进行一个排列 且是唯一的 不能与明天或者前天的相同
接着在这里方法内获取当前系统日期 然后来对0-50进行一个排列 且是唯一的 不能与明天或者前天的相同
解决方案 »
- java里面有没有直接操控显示缓冲的方法呢?
- JComboBox 列表更新 应该加入到什么事件当中(帮吗优化代码)
- 请教一个有关随机的算法
- java 还是LINUX嵌入式???
- 要想把一个大于128的整数保存在byte中(取时以无符号数读出)要怎么做
- 我的Applet程序为什么不能在Appletviewer下运行呢?
- 求助!java swing 里的焦点问题,各位大虾来帮帮忙啊!
- 能反编译CLASS成JAVA原代码吗?
- what a java could be?-----let's talk in english!($_$)
- 高分请教:有谁了解JAVA多线程技术啊.在一个线程中再启动多个线程.
- JAVA和NOTEPADE++的难题
- 关于键盘输入Tab后,如何控制焦点,这个问题我觉得有点难度
import java.util.Arrays;public class Test {
public static void main(String[] args) {
System.out.println(Arrays.toString((mySort(30))));
}
public static int[] mySort(int num){
int[] before=new int[num+1];
int[] after=new int[num+1];
for(int i=0;i<=num;i++){
before[i]=i;
}
for(int i=0,j=0;i<=num;i++,j++){
int index=(int)(Math.random()*num);
if(before[index]!=-1){
after[j]=before[index];
before[index]=-1;
}else{
while(before[index]==-1){
index++;
if(index==num+1)
index=0;
}
after[j]=before[index];
before[index]=-1;
}
//System.out.println(Arrays.toString(before));
}
return after;
}
}
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Random;public class Test {
public static void main(String[] args) {
System.out.println(Arrays.toString((mySort(30))));
}
public static int[] mySort(int num){
Date d=new Date();
SimpleDateFormat f=new SimpleDateFormat("yyyyddMM");
long n=Integer.parseInt(f.format(d));
Random ran=new Random(n);
System.out.println(n);
int[] before=new int[num+1];
int[] after=new int[num+1];
for(int i=0;i<=num;i++){
before[i]=i;
}
for(int i=0,j=0;i<=num;i++,j++){
int index=ran.nextInt(num);
if(before[index]!=-1){
after[j]=before[index];
before[index]=-1;
}else{
while(before[index]==-1){
index++;
if(index==num+1)
index=0;
}
after[j]=before[index];
before[index]=-1;
}
}
return after;
}
}今天的排列:
[18, 19, 29, 17, 20, 6, 23, 21, 3, 16, 9, 13, 14, 4, 22, 10, 26, 24, 15, 11, 28, 12, 25, 5, 7, 27, 30, 0, 1, 2, 8]
明天的排列:
[23, 9, 11, 2, 7, 19, 21, 3, 18, 25, 10, 4, 20, 12, 8, 15, 16, 13, 17, 0, 5, 22, 6, 14, 24, 26, 27, 28, 29, 30, 1]
只要把这句改成Random ran=new Random(20091608);就行了
预知下个时刻就不好说了
公式应该是有的 只是我不知道 可以考虑看下random的源码
要知道明天么你运行下就行了