当前位置: 技术问答>java相关
请给一个随机数产生的java程序?
来源: 互联网 发布时间:2015-05-10
本文导语: 请给一个随机数产生的java程序? 要求能通过触发产生一个随机数在1--100。一次触发产生一个输出,要多次触发时不能输出同样的数值。 万分感谢!! | GENERATING INTEGER RANDOM NUMBERS There...
请给一个随机数产生的java程序?
要求能通过触发产生一个随机数在1--100。一次触发产生一个输出,要多次触发时不能输出同样的数值。
万分感谢!!
要求能通过触发产生一个随机数在1--100。一次触发产生一个输出,要多次触发时不能输出同样的数值。
万分感谢!!
|
GENERATING INTEGER RANDOM NUMBERS
There are many ways to generate random numbers with the base libraries found in the Java 2 SDK, Standard Edition. If you haven't kept up to date with changes to the libraries, you might be using an inefficient mechanism or, possibly worse, getting results that are not uniformly distributed. Here's a look at a good way to generate integer random numbers, and then a look at what's not so good about some other ways.
The java.util.Random class has been available for generating random numbers since the initial release of the system libraries. Starting with the 1.2 release of the Java 2 SDK, Standard Edition, the Random class has a nextInt() method that accepts an integer argument:
public int nextInt(int n)
Given some value n, nextInt(n) returns a value greater than or equal to zero but less then that value: 0
There are many ways to generate random numbers with the base libraries found in the Java 2 SDK, Standard Edition. If you haven't kept up to date with changes to the libraries, you might be using an inefficient mechanism or, possibly worse, getting results that are not uniformly distributed. Here's a look at a good way to generate integer random numbers, and then a look at what's not so good about some other ways.
The java.util.Random class has been available for generating random numbers since the initial release of the system libraries. Starting with the 1.2 release of the Java 2 SDK, Standard Edition, the Random class has a nextInt() method that accepts an integer argument:
public int nextInt(int n)
Given some value n, nextInt(n) returns a value greater than or equal to zero but less then that value: 0
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!