java 改变seed值,Java中的默认种子PRNG

编程入门 行业动态 更新时间:2024-10-28 08:24:08

java 改变seed值,Java中的默认<a href=https://www.elefans.com/category/jswz/34/1769131.html style=种子PRNG"/>

java 改变seed值,Java中的默认种子PRNG

I was wondering what the default seed for the PRNG* behind Math.random() in Java is. From what I understand the one in C is based upon the system clock. So is it similar in Java? Also, is the seed changed everytime Math.random() is called?

*PRNG = Pseudo Random Number Generator

解决方案

When this method is first called, it creates a single new

pseudorandom-number generator, exactly as if by the expression

new java.util.Random()

This new pseudorandom-number generator is used

thereafter for all calls to this method and is used nowhere else.

Following up with java.util.Random(), the documentation says

public Random()

Creates a new random number generator. This constructor sets the seed

of the random number generator to a value very likely to be distinct

from any other invocation of this constructor.

The current implementation appears to be based on System.nanoTime() but could change and still be compliant with the documentation's contract.

As for changing the seed with every call, that's not how seeds work. PRNGs are seeded once, and then produce a sequence of values that evolve from that initial state. You shouldn't, and Java doesn't, keep re-seeding.

更多推荐

java 改变seed值,Java中的默认种子PRNG

本文发布于:2024-02-12 17:13:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1688689.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:种子   seed   java   PRNG   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!