topic You probably mean 10**6 and in IntelĀ® Fortran Compiler
https://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185900#M150023
<P>You probably mean 10**6 and 10**11.</P><P>The number of distinct random integers that you can produce this way is limited by the number of single-precision numbers that fit in the interval 0-1.0. If you want to go up to 10**11, then you will see more or less systematic gaps between the generated numbers, as the number of decimals is 5 to 6, so at most 10**5 distinct numbers in that interval. It is possible to be more precise than that, but this should give you a rough idea.</P>Thu, 11 Jun 2020 11:18:39 GMTArjen_Markus2020-06-11T11:18:39ZRandom-Number generator question about single precision
https://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185899#M150022
<P>I'm just curious about this: I want a random uniform integer between and inclusive of 1 and 1**6. To get this, I use a single precision real and the following code:</P><P>My code is </P><P>integer, parameter :: SinglePrecision = selected_real_kind(5) </P><P>real (kind = SinglePrecision) ARandomReal</P><P>Call Random_Number(ARandomReal)</P><P>Print *, Ceiling( (1.0-ARandomReal)*1**6)</P><P>Now, here is the question: Suppose I asked for an integer between 1 and 1**11? I'm sure the random number generator would fail. A single precision real cannot be mapped one-to-one to such a large integer, but where would this go wrong? I've done a quick test, and the numbers still look random, but I haven't dug deep into the tests for randomness.</P><P>Any theories on how Random_Number would go wrong.</P>Sun, 07 Jun 2020 17:27:00 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185899#M150022pike__christopher2020-06-07T17:27:00ZYou probably mean 10**6 and
https://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185900#M150023
<P>You probably mean 10**6 and 10**11.</P><P>The number of distinct random integers that you can produce this way is limited by the number of single-precision numbers that fit in the interval 0-1.0. If you want to go up to 10**11, then you will see more or less systematic gaps between the generated numbers, as the number of decimals is 5 to 6, so at most 10**5 distinct numbers in that interval. It is possible to be more precise than that, but this should give you a rough idea.</P>Thu, 11 Jun 2020 11:18:39 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185900#M150023Arjen_Markus2020-06-11T11:18:39ZFrom: https://software.intel
https://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185901#M150024
<P>From: <A href="https://software.intel.com/content/www/us/en/develop/documentation/fortran-compiler-developer-guide-and-reference/top/language-reference/a-to-z-reference/q-to-r/random-number.html" target="_blank">https://software.intel.com/content/www/us/en/develop/documentation/fortran-compiler-developer-guide-and-reference/top/language-reference/a-to-z-reference/q-to-r/random-number.html</A></P><P>The RANDOM_NUMBER generator uses two separate congruential generators together to produce a period of approximately 10**18, and produces real pseudorandom results with a uniform distribution in [0, 1). It accepts two integer seeds, the first of which is reduced to the range [1, 2147483562]. The second seed is reduced to the range [1, 2147483398]. This means that the generator effectively uses two 31-bit seeds.</P><P>This seems to imply that internally, the result will be generated internally as a 62-bit integer result that is then partially used as the mantissa of the floating point REAL result. Typically a center portion of the 62-bit product (23 bits) is excised for the mantissa. It is unclear that DRAND or DRANDM is called when a DOUBLEPRECISION scalar/array is used as an argument .OR. that the internally produced REAL is promoted to DOUBLEPRECISION.</P><P>While spreading the range, as Arjen reports is adequate for your purposes, when it is not, consider something like:</P>
<PRE class="brush:fortran; class-name:dark;">integer, parameter :: SinglePrecision = selected_real_kind(5)
integer, parameter :: DoublePrecision = selected_real_kind(11)
real (kind = SinglePrecision) ARandomReal
real (kind = DoublePrecision) ARandomDouble
Call Random_Number(ARandomReal)
Call Random_Number(ARandomDouble)
ARandomDouble = ARandomDouble * ARandomReal
Print *, Ceiling( (1.0_DoublePrecision-ARandomDouble)*(10_DoublePrecision**11) )</PRE>
<P>*** The above ASSUMES Random_Number internally produces a SinglePrecision REAL. If it does not, then the above is not necessary.</P>
<P>Jim Dempsey</P>Thu, 11 Jun 2020 12:54:53 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185901#M150024jimdempseyatthecove2020-06-11T12:54:53ZYou should be using MKL
https://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185902#M150025
<P>You should be using MKL random number generators --</P>Thu, 11 Jun 2020 15:41:16 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185902#M150025JohnNichols2020-06-11T15:41:16ZThanks for the answers.
https://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185903#M150026
<P>Thanks for the answers. These sort of confirm my guess, which is that the random integers I try to generate would develop gaps. As for the MKL generator, I'm sort of making the assumption that the people who wrote fortran are smarter than me, so I use theirs. </P>Mon, 15 Jun 2020 00:36:23 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185903#M150026pike__christopher2020-06-15T00:36:23ZThe scholar George Marsaglia
https://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185904#M150027
<P>The scholar George Marsaglia (1924-2011) wrote a famous paper on this property of some classes of pseudo-random numbers.</P><P>Marsaglia's Theorem: <STRONG>Random numbers fall mainly in the planes</STRONG>. See https://www.pnas.org/content/pnas/61/1/25.full.pdf .</P>Mon, 15 Jun 2020 01:50:34 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Random-Number-generator-question-about-single-precision/m-p/1185904#M150027mecej42020-06-15T01:50:34Z