《Java编程技巧1001条》354条:了解伪随机与真随机
2017-12-19 13:02
405 查看
《Java编程技巧1001条》354条:了解伪随机与真随机
354Understanding Pseudo Random Versus True Random
354 弄清伪随机数与真随机数
When Java, or most other computer languages,needs to produce a random number, a special calculation is made based on agiven input value called a seed number. The calculation will always produce thesame number when the same seed number is given. Because the
functions result isalways predictable, it is called a pseudo-random number. A true-random numberis not predictable. The fact that the pseudo-random number is predictable doesnot mean that it cannot make a good random number. The seed number in Java is64 bits
long and the algorithm which uses it to create a - 11 - random numberproduces a good distribution of values. A big advantage of pseudo-randomnumbers is that your program is easier to debug when it uses the same sequenceof random numbers. After you release
your software to users, you can ensuregood randomness by using a different seed for each program run. For example,the seed could be based on the time, user keystrokes, network activity, or anyother random phenomena. 当 Java,或其它计算机语言, 需要产生一随机数时, 就要利用一个称作种子(数)的已知输
入数来进行一种特殊的计算. 当给出的是同一种子时, 则计算的结果也永远是相同的一个数. 这是因为,函数的计算总是确定的, 其结果也就总是可以预测的. 所以,这样的随机数叫伪随机 数. 真随机数则应该是不确定的, 不可预测的. 伪随机数的可预测性并不意味它不能造就出一个好的随机数. Java 的种子数是 64 位的长 整数,它用来产生随机数的算法能产生数值分布很好的随机数. 伪随机数的一个很大优点在于它可使你的程序容易调试,因为它可以使用相同序列的一 串数. 当你把你的软件交给用户使用后,你可以让每一次运行使用不同的种子以保证产生很好
的随机性. 例如,你可以根据当时的时间,用户的击键次数,网络的作业,或其它随机现象来计算 种子的数值.
354Understanding Pseudo Random Versus True Random
354 弄清伪随机数与真随机数
When Java, or most other computer languages,needs to produce a random number, a special calculation is made based on agiven input value called a seed number. The calculation will always produce thesame number when the same seed number is given. Because the
functions result isalways predictable, it is called a pseudo-random number. A true-random numberis not predictable. The fact that the pseudo-random number is predictable doesnot mean that it cannot make a good random number. The seed number in Java is64 bits
long and the algorithm which uses it to create a - 11 - random numberproduces a good distribution of values. A big advantage of pseudo-randomnumbers is that your program is easier to debug when it uses the same sequenceof random numbers. After you release
your software to users, you can ensuregood randomness by using a different seed for each program run. For example,the seed could be based on the time, user keystrokes, network activity, or anyother random phenomena. 当 Java,或其它计算机语言, 需要产生一随机数时, 就要利用一个称作种子(数)的已知输
入数来进行一种特殊的计算. 当给出的是同一种子时, 则计算的结果也永远是相同的一个数. 这是因为,函数的计算总是确定的, 其结果也就总是可以预测的. 所以,这样的随机数叫伪随机 数. 真随机数则应该是不确定的, 不可预测的. 伪随机数的可预测性并不意味它不能造就出一个好的随机数. Java 的种子数是 64 位的长 整数,它用来产生随机数的算法能产生数值分布很好的随机数. 伪随机数的一个很大优点在于它可使你的程序容易调试,因为它可以使用相同序列的一 串数. 当你把你的软件交给用户使用后,你可以让每一次运行使用不同的种子以保证产生很好
的随机性. 例如,你可以根据当时的时间,用户的击键次数,网络的作业,或其它随机现象来计算 种子的数值.
相关文章推荐
- 《Java编程技巧1001条》353条:求随机浮点数
- 《Java编程技巧1001条》第604条:了解图像的观察器
- 《Java编程技巧1001条》第373条: 了解不同的日期标准,
- 《Java 编程技巧1001条》第402-406条: 了解事件驱动程序,
- 《Java 编程技巧1001条》 第403条: 了解事件类
- 《Java编程技巧1001条》第609条: 建立推进特殊效果
- 《Java编程技巧1001条》 第345条:使用ceil方法
- 《Java编程技巧1001条》360-373条:用日期函数获得当前日期
- 《Java 编程技巧1001条》 第404条: 了解实用方法
- 《Java编程技巧1001条》第600条: 重用update方法来减少图像闪烁
- 《Java编程技巧1001条》第607条: 利用MediaTraker预装图像
- 《Java编程技巧1001条》 第346条:浮点数向上向下舍入方法
- 《Java编程技巧1001条》第608条: 在装入图像时设置时间限制
- 《Java编程技巧1001条》第375条: 使用DOS下的 TZ 环境变量,
- 《Java 编程技巧1001条》 第392条: 了解2分查找
- 《Java编程技巧1001条》第591-609条 播放声音剪辑
- 《Java编程技巧1001条》第362条: 用日期类 建立你自己的 日期/时间
- 《Java 编程技巧1001条》第414条:了解键盘事件
- 《Java编程技巧1001条》第603条: 使用双缓冲器改进动画
- 《JAVA编程技巧1001条》第334条:数学函数 求绝对值.