📄 random.html
字号:
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=1><FONT SIZE="+2">
<B>Constructor Detail</B></FONT></TD>
</TR>
</TABLE>
<A NAME="Random()"><!-- --></A><H3>
Random</H3>
<PRE>
public <B>Random</B>()</PRE>
<DL>
<DD>Creates a new random number generator. Its seed is initialized to a value based on the current time: <blockquote><pre> public Random() { this(System.currentTimeMillis()); }</pre></blockquote><DD><DL>
<DT><B>See Also: </B><DD><A HREF="../../java/lang/System.html#currentTimeMillis()"><CODE>System.currentTimeMillis()</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="Random(long)"><!-- --></A><H3>
Random</H3>
<PRE>
public <B>Random</B>(long seed)</PRE>
<DL>
<DD>Creates a new random number generator using a single <code>long</code> seed: <blockquote><pre> public Random(long seed) { setSeed(seed); }</pre></blockquote> Used by method <tt>next</tt> to hold the state of the pseudorandom number generator.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>seed</CODE> - the initial seed.<DT><B>See Also: </B><DD><A HREF="../../java/util/Random.html#setSeed(long)"><CODE>setSeed(long)</CODE></A></DL>
</DD>
</DL>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=1><FONT SIZE="+2">
<B>Method Detail</B></FONT></TD>
</TR>
</TABLE>
<A NAME="setSeed(long)"><!-- --></A><H3>
setSeed</H3>
<PRE>
public void <B>setSeed</B>(long seed)</PRE>
<DL>
<DD>Sets the seed of this random number generator using a single <code>long</code> seed. The general contract of <tt>setSeed</tt> is that it alters the state of this random number generator object so as to be in exactly the same state as if it had just been created with the argument <tt>seed</tt> as a seed. The method <tt>setSeed</tt> is implemented by class Random as follows: <blockquote><pre> synchronized public void setSeed(long seed) { this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1); }</pre></blockquote> The implementation of <tt>setSeed</tt> by class <tt>Random</tt> happens to use only 48 bits of the given seed. In general, however, an overriding method may use all 64 bits of the long argument as a seed value.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>seed</CODE> - the initial seed.</DL>
</DD>
</DL>
<HR>
<A NAME="next(int)"><!-- --></A><H3>
next</H3>
<PRE>
protected int <B>next</B>(int bits)</PRE>
<DL>
<DD>Generates the next pseudorandom number. Subclass should override this, as this is used by all other methods.<p> The general contract of <tt>next</tt> is that it returns an <tt>int</tt> value and if the argument bits is between <tt>1</tt> and <tt>32</tt> (inclusive), then that many low-order bits of the returned value will be (approximately) independently chosen bit values, each of which is (approximately) equally likely to be <tt>0</tt> or <tt>1</tt>. The method <tt>next</tt> is implemented by class <tt>Random</tt> as follows: <blockquote><pre> synchronized protected int next(int bits) { seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1); return (int)(seed >>> (48 - bits)); }</pre></blockquote> This is a linear congruential pseudorandom number generator, as defined by D. H. Lehmer and described by Donald E. Knuth in <i>The Art of Computer Programming,</i> Volume 2: <i>Seminumerical Algorithms</i>, section 3.2.1.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>bits</CODE> - random bits<DT><B>Returns:</B><DD>the next pseudorandom value from this random number generator's sequence.<DT><B>Since: </B><DD>JDK1.1</DD>
</DL>
</DD>
</DL>
<HR>
<A NAME="nextInt()"><!-- --></A><H3>
nextInt</H3>
<PRE>
public int <B>nextInt</B>()</PRE>
<DL>
<DD>Returns the next pseudorandom, uniformly distributed <code>int</code> value from this random number generator's sequence. The general contract of <tt>nextInt</tt> is that one <tt>int</tt> value is pseudorandomly generated and returned. All 2<font size="-1"><sup>32 </sup></font> possible <tt>int</tt> values are produced with (approximately) equal probability. The method <tt>nextInt</tt> is implemented by class <tt>Random</tt> as follows: <blockquote><pre> public int nextInt() { return next(32); }</pre></blockquote><DD><DL>
<DT><B>Returns:</B><DD>the next pseudorandom, uniformly distributed <code>int</code> value from this random number generator's sequence.</DL>
</DD>
</DL>
<HR>
<A NAME="nextLong()"><!-- --></A><H3>
nextLong</H3>
<PRE>
public long <B>nextLong</B>()</PRE>
<DL>
<DD>Returns the next pseudorandom, uniformly distributed <code>long</code> value from this random number generator's sequence. The general contract of <tt>nextLong</tt> is that one long value is pseudorandomly generated and returned. All 2<font size="-1"><sup>64</sup></font> possible <tt>long</tt> values are produced with (approximately) equal probability. The method <tt>nextLong</tt> is implemented by class <tt>Random</tt> as follows: <blockquote><pre> public long nextLong() { return ((long)next(32) << 32) + next(32); }</pre></blockquote><DD><DL>
<DT><B>Returns:</B><DD>the next pseudorandom, uniformly distributed <code>long</code> value from this random number generator's sequence.</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_bottom"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Random.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
<strong>MID Profile</strong></EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../java/util/Hashtable.html"><B>PREV CLASS</B></A>
<A HREF="../../java/util/Stack.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A>
<A HREF="Random.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: INNER | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
<font size="-1"><a href="mailto:midp-feedback@risc.sps.mot.com">Submit a comment or suggestion</a> Version 2.0 of MID Profile Specification<br>Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries. Copyright (c) 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road,Palo Alto, California, 94303, U.S.A. All Rights Reserved.</font>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -