java - 保存并重新使用这个“随机”?
问题描述
出于某种原因,我创建的 Random 对象出现错误,我看不出任何原因。有人可以帮忙吗?我将不胜感激!
public static void experiment(String method, String testType, int arraySize, int trials){
int[] intArray = new int[arraySize];
Random rand = new Random();
Long startTime;
Long endTime;
Long duration;
String durationStr;
String arraySizeStr = String.valueOf(arraySize);
for (int i =0; i<arraySize;i++){
intArray[i] = i;
}
if (method=="exhaustive"){
if (testType =="worst"){
for (int j = 0; j<= trials; j++){
startTime = System.currentTimeMillis();
exhaustive(intArray, intArray[arraySize-1]*3);
endTime = System.currentTimeMillis();
duration = endTime - startTime;
durationStr = duration.toString();
System.out.println("Exhaustive, Worst, " + durationStr + ", Array Size: " + arraySizeStr);
}
}
else{
for (int j = 0; j<= trials; j++){
startTime = System.currentTimeMillis();
exhaustive(intArray, rand.nextInt((arraySize -1) * 2));
endTime = System.currentTimeMillis();
duration = endTime - startTime;
durationStr = duration.toString();
System.out.println("Exhaustive, Best, " + durationStr + ", Array Size: " + arraySizeStr);
}
}
}
解决方案
推荐阅读
- android - 如何在Android中使用retrofit2解析jsonObject发送到字符串?
- ruby-on-rails - 如何从 check_box 中获取哈希值?
- python - 更改张量流图并恢复训练
- java - 如果页面异步更改其内容(无需重新加载页面),如何制作 WebDriverWait?
- assembly - 我正在尝试使用程序集从 1 添加到 10,我必须使用 DI 寄存器
- python - 如何在 python 类中使用概率分布?
- html - 我的引导模式默认打开/损坏
- ros - SLAM/VO中的数据关联和特征匹配有什么区别?
- python - Shopify Django 应用程序:printf:警告:忽略多余的参数,以“;”开头
- google-bigquery - BigQuery:使用分片表将表插入到现有的谷歌分析中