<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.4.2_03) on Mon Oct 10 16:31:47 CEST 2005 -->
<TITLE>
Random (IM Profile)
</TITLE>

<META NAME="keywords" CONTENT="java.util.Random class">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">

<SCRIPT type="text/javascript">
function windowTitle()
{
    parent.document.title="Random (IM Profile)";
}
</SCRIPT>

</HEAD>

<BODY BGCOLOR="white" onload="windowTitle();">


<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A>
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
  <TR ALIGN="center" VALIGN="top">
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/Random.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  </TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
<strong>IM Profile</strong></EM>
</TD>
</TR>

<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../java/util/Hashtable.html" title="class in java.util"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../java/util/Stack.html" title="class in java.util"><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>  &nbsp;
&nbsp;<A HREF="Random.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
&nbsp;<SCRIPT type="text/javascript">
  <!--
  if(window==top) {
    document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');
  }
  //-->
</SCRIPT>
<NOSCRIPT>
  <A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>

</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A>
<!-- ========= END OF TOP NAVBAR ========= -->

<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
java.util</FONT>
<BR>
Class Random</H2>
<PRE>
<A HREF="../../java/lang/Object.html" title="class in java.lang">java.lang.Object</A>
  <IMG SRC="../../resources/inherit.gif" ALT="extended by"><B>java.util.Random</B>
</PRE>
<HR>
<DL>
<DT>public class <B>Random</B><DT>extends <A HREF="../../java/lang/Object.html" title="class in java.lang">Object</A></DL>

<P>
An instance of this class is used to generate a stream of
 pseudorandom numbers. The class uses a 48-bit seed, which is
 modified using a linear congruential formula. (See Donald Knuth,
 <i>The Art of Computer Programming, Volume 2</i>, Section 3.2.1.)
 <p>
 If two instances of <code>Random</code> are created with the same
 seed, and the same sequence of method calls is made for each, they
 will generate and return identical sequences of numbers. In order to
 guarantee this property, particular algorithms are specified for the
 class <tt>Random</tt>. Java implementations must use all the algorithms
 shown here for the class <tt>Random</tt>, for the sake of absolute
 portability of Java code. However, subclasses of class <tt>Random</tt>
 are permitted to use other algorithms, so long as they adhere to the
 general contracts for all the methods.
 <p>
 The algorithms implemented by class <tt>Random</tt> use a
 <tt>protected</tt> utility method that on each invocation can supply
 up to 32 pseudorandomly generated bits.
 <p>
<P>

<P>
<DL>
<DT><B>Since:</B></DT>
  <DD>JDK1.0, CLDC 1.0</DD>
</DL>
<HR>

<P>
<!-- ======== NESTED CLASS SUMMARY ======== -->


<!-- =========== FIELD SUMMARY =========== -->


<!-- ======== CONSTRUCTOR SUMMARY ======== -->

<A NAME="constructor_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Constructor Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../java/util/Random.html#Random()">Random</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creates a new random number generator. </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../java/util/Random.html#Random(long)">Random</A></B>(long&nbsp;seed)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creates a new random number generator using a single
 <code>long</code> seed:
 
 public Random(long seed) { setSeed(seed); }
 Used by method <tt>next</tt> to hold
 the state of the pseudorandom number generator.</TD>
</TR>
</TABLE>
&nbsp;
<!-- ========== METHOD SUMMARY =========== -->

<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Method Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected &nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../java/util/Random.html#next(int)">next</A></B>(int&nbsp;bits)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Generates the next pseudorandom number. </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;double</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../java/util/Random.html#nextDouble()">nextDouble</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the next pseudorandom, uniformly distributed
 <code>double</code> value between <code>0.0</code> and
 <code>1.0</code> from this random number generator's sequence. </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;float</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../java/util/Random.html#nextFloat()">nextFloat</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the next pseudorandom, uniformly distributed <code>float</code>
 value between <code>0.0</code> and <code>1.0</code> from this random
 number generator's sequence. </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../java/util/Random.html#nextInt()">nextInt</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the next pseudorandom, uniformly distributed <code>int</code>
 value from this random number generator's sequence. </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../java/util/Random.html#nextInt(int)">nextInt</A></B>(int&nbsp;n)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a pseudorandom, uniformly distributed <tt>int</tt> value
 between 0 (inclusive) and the specified value (exclusive), drawn from
 this random number generator's sequence.  </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;long</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../java/util/Random.html#nextLong()">nextLong</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the next pseudorandom, uniformly distributed <code>long</code>
 value from this random number generator's sequence. </TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../java/util/Random.html#setSeed(long)">setSeed</A></B>(long&nbsp;seed)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets the seed of this random number generator using a single
 <code>long</code> seed. </TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TD><B>Methods inherited from class java.lang.<A HREF="../../java/lang/Object.html" title="class in java.lang">Object</A></B></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><A HREF="../../java/lang/Object.html#equals(java.lang.Object)">equals</A>, <A HREF="../../java/lang/Object.html#getClass()">getClass</A>, <A HREF="../../java/lang/Object.html#hashCode()">hashCode</A>, <A HREF="../../java/lang/Object.html#notify()">notify</A>, <A HREF="../../java/lang/Object.html#notifyAll()">notifyAll</A>, <A HREF="../../java/lang/Object.html#toString()">toString</A>, <A HREF="../../java/lang/Object.html#wait()">wait</A>, <A HREF="../../java/lang/Object.html#wait(long)">wait</A>, <A HREF="../../java/lang/Object.html#wait(long, int)">wait</A></CODE></TD>
</TR>
</TABLE>
&nbsp;
<P>

<!-- ============ FIELD DETAIL =========== -->


<!-- ========= CONSTRUCTOR DETAIL ======== -->

<A NAME="constructor_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<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>
<P>
<DT><B>See Also:</B><DD><A HREF="../../java/lang/System.html#currentTimeMillis()"><CODE>System.currentTimeMillis()</CODE></A></DL>
<HR>

<A NAME="Random(long)"><!-- --></A><H3>
Random</H3>
<PRE>
public <B>Random</B>(long&nbsp;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.
<P>
<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>

<!-- ============ METHOD DETAIL ========== -->

<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<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&nbsp;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.
<P>
<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&nbsp;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.
<P>
<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.</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>
<P>
<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="nextInt(int)"><!-- --></A><H3>
nextInt</H3>
<PRE>
public int <B>nextInt</B>(int&nbsp;n)</PRE>
<DL>
<DD>Returns a pseudorandom, uniformly distributed <tt>int</tt> value
 between 0 (inclusive) and the specified value (exclusive), drawn from
 this random number generator's sequence.  The general contract of
 <tt>nextInt</tt> is that one <tt>int</tt> value in the specified range
 is pseudorandomly generated and returned.  All <tt>n</tt> possible
 <tt>int</tt> values are produced with (approximately) equal
 probability.  The method <tt>nextInt(int n)</tt> is implemented by
 class <tt>Random</tt> as follows:
 <blockquote><pre>
 public int nextInt(int n) {
     if (n<=0)
         throw new IllegalArgumentException("n must be positive");

     if ((n & -n) == n)  // i.e., n is a power of 2
         return (int)((n * (long)next(31)) >> 31);

     int bits, val;
     do {
         bits = next(31);
         val = bits % n;
     } while(bits - val + (n-1) < 0);
     return val;
 }
 </pre></blockquote>
 <p>
 The hedge "approximately" is used in the foregoing description only
 because the next method is only approximately an unbiased source of
 independently chosen bits.  If it were a perfect source of randomly
 chosen bits, then the algorithm shown would choose <tt>int</tt>
 values from the stated range with perfect uniformity.
 <p>
 The algorithm is slightly tricky.  It rejects values that would result
 in an uneven distribution (due to the fact that 2^31 is not divisible
 by n). The probability of a value being rejected depends on n.  The
 worst case is n=2^30+1, for which the probability of a reject is 1/2,
 and the expected number of iterations before the loop terminates is 2.
 <p>
 The algorithm treats the case where n is a power of two specially: it
 returns the correct number of high-order bits from the underlying
 pseudo-random number generator.  In the absence of special treatment,
 the correct number of <i>low-order</i> bits would be returned.  Linear
 congruential pseudo-random number generators such as the one
 implemented by this class are known to have short periods in the
 sequence of values of their low-order bits.  Thus, this special case
 greatly increases the length of the sequence of values returned by
 successive calls to this method if n is a small power of two.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>n</CODE> - the bound on the random number to be returned.  Must be
          positive.
<DT><B>Returns:</B><DD>a pseudorandom, uniformly distributed <tt>int</tt>
          value between 0 (inclusive) and n (exclusive).
<DT><B>Throws:</B>
<DD><CODE><A HREF="../../java/lang/IllegalArgumentException.html" title="class in java.lang">IllegalArgumentException</A></CODE> - n is not positive.<DT><B>Since:</B></DT>
  <DD>CLDC 1.1</DD>
</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>
<P>
<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>
<HR>

<A NAME="nextFloat()"><!-- --></A><H3>
nextFloat</H3>
<PRE>
public float <B>nextFloat</B>()</PRE>
<DL>
<DD>Returns the next pseudorandom, uniformly distributed <code>float</code>
 value between <code>0.0</code> and <code>1.0</code> from this random
 number generator's sequence. <p>
 The general contract of <tt>nextFloat</tt> is that one <tt>float</tt>
 value, chosen (approximately) uniformly from the range <tt>0.0f</tt>
 (inclusive) to <tt>1.0f</tt> (exclusive), is pseudorandomly
 generated and returned. All 2<font size="-1"><sup>24</sup></font>
 possible <tt>float</tt> values of the form
 <i>m&nbsp;x&nbsp</i>2<font size="-1"><sup>-24</sup></font>, where
 <i>m</i> is a positive integer less than 2<font size="-1"><sup>24</sup>
 </font>, are produced with (approximately) equal probability. The
 method <tt>nextFloat</tt> is implemented by class <tt>Random</tt> as
 follows:
 <blockquote><pre>
 public float nextFloat() {
      return next(24) / ((float)(1 << 24));
 }</pre></blockquote>
 The hedge "approximately" is used in the foregoing description only
 because the next method is only approximately an unbiased source of
 independently chosen bits. If it were a perfect source or randomly
 chosen bits, then the algorithm shown would choose <tt>float</tt>
 values from the stated range with perfect uniformity.<p>
 [In early versions of Java, the result was incorrectly calculated as:
 <blockquote><pre>
 return next(30) / ((float)(1 << 30));</pre></blockquote>
 This might seem to be equivalent, if not better, but in fact it
 introduced a slight nonuniformity because of the bias in the rounding
 of floating-point numbers: it was slightly more likely that the
 low-order bit of the significand would be 0 than that it would be 1.]
<P>
<DD><DL>

<DT><B>Returns:</B><DD>the next pseudorandom, uniformly distributed <code>float</code>
          value between <code>0.0</code> and <code>1.0</code> from this
          random number generator's sequence.<DT><B>Since:</B></DT>
  <DD>CLDC 1.1</DD>
</DL>
</DD>
</DL>
<HR>

<A NAME="nextDouble()"><!-- --></A><H3>
nextDouble</H3>
<PRE>
public double <B>nextDouble</B>()</PRE>
<DL>
<DD>Returns the next pseudorandom, uniformly distributed
 <code>double</code> value between <code>0.0</code> and
 <code>1.0</code> from this random number generator's sequence. <p>
 The general contract of <tt>nextDouble</tt> is that one
 <tt>double</tt> value, chosen (approximately) uniformly from the
 range <tt>0.0d</tt> (inclusive) to <tt>1.0d</tt> (exclusive), is
 pseudorandomly generated and returned. All
 2<font size="-1"><sup>53</sup></font> possible <tt>float</tt>
 values of the form <i>m&nbsp;x&nbsp;</i>2<font size="-1"><sup>-53</sup>
 </font>, where <i>m</i> is a positive integer less than
 2<font size="-1"><sup>53</sup></font>, are produced with
 (approximately) equal probability. The method <tt>nextDouble</tt> is
 implemented by class <tt>Random</tt> as follows:
 <blockquote><pre>
 public double nextDouble() {
       return (((long)next(26) << 27) + next(27))
           / (double)(1L << 53);
 }</pre></blockquote><p>
 The hedge "approximately" is used in the foregoing description only
 because the <tt>next</tt> method is only approximately an unbiased
 source of independently chosen bits. If it were a perfect source or
 randomly chosen bits, then the algorithm shown would choose
 <tt>double</tt> values from the stated range with perfect uniformity.
 <p>[In early versions of Java, the result was incorrectly calculated as:
 <blockquote><pre>
  return (((long)next(27) << 27) + next(27))
      / (double)(1L << 54);</pre></blockquote>
 This might seem to be equivalent, if not better, but in fact it
 introduced a large nonuniformity because of the bias in the rounding
 of floating-point numbers: it was three times as likely that the
 low-order bit of the significand would be 0 than that it would be
 1! This nonuniformity probably doesn't matter much in practice, but
 we strive for perfection.]
<P>
<DD><DL>

<DT><B>Returns:</B><DD>the next pseudorandom, uniformly distributed
          <code>double</code> value between <code>0.0</code> and
          <code>1.0</code> from this random number generator's sequence.<DT><B>Since:</B></DT>
  <DD>CLDC 1.1</DD>
</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>


<!-- ======= START OF BOTTOM NAVBAR ====== -->
<A NAME="navbar_bottom"><!-- --></A>
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
  <TR ALIGN="center" VALIGN="top">
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/Random.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  </TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
<strong>IM Profile</strong></EM>
</TD>
</TR>

<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../java/util/Hashtable.html" title="class in java.util"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../java/util/Stack.html" title="class in java.util"><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>  &nbsp;
&nbsp;<A HREF="Random.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
&nbsp;<SCRIPT type="text/javascript">
  <!--
  if(window==top) {
    document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>');
  }
  //-->
</SCRIPT>
<NOSCRIPT>
  <A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>

</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->

<HR>
<font size=\-1\><a href=\mailto:midp-feedback@risc.sps.mot.com\>Submit a comment or suggestion</a> Version 2.0 of IM 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>
