java for循环执行得太快会导致System.currentTimeMillis()重复 [英] java for loop executes too fast gives System.currentTimeMillis() duplicate
本文介绍了java for循环执行得太快会导致System.currentTimeMillis()重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用System.currentTimeMillis()在foor循环中产生唯一值问题是循环执行太快,System.currentTimeMillis()给我重复的值。
我怎样才能产生确定的唯一值。
< pre $ for(int a = 0; a< = 10; a ++){
System.out.println(System.currentTimeMillis())
}
我也试过,但是也不能生成唯一的数字
System.currentTimeMillis()+ Math.random()
System.nanoTime()来代替?
Java: I have a problem using System.currentTimeMillis() function
i am using System.currentTimeMillis() to generate unique values in foor loop problem is loop executes too fast and System.currentTimeMillis() gives me duplicate values.
How can i generate for sure unique values.
for(int a=0;a<=10;a++){
System.out.println(System.currentTimeMillis())
}
I also tried following but it is also not generaet to generate unique number
System.currentTimeMillis()+Math.random()
解决方案
why don't you use System.nanoTime()
instead?
这篇关于java for循环执行得太快会导致System.currentTimeMillis()重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文