Re: random_number



James Giles wrote in message ...
>robin wrote:
>...
>> There's nothing "fundamentally flawed" about the method,
>> as the following proves. Below are printed the first ten values
>> below 1.0 (left-hand column) and their products (right-hand column)
>> with
>> the nearest value above 1.0 :- Only the least-significant 8 bits of
>> each mantissa are printed.
>>
>> 11111111 00000000
>> 11111110 11111111
>> 11111101 11111110
>> 11111100 11111101
>> 11111011 11111100
>> 11111010 11111011
>> 11111001 11111010
>> 11111000 11111001
>> 11110111 11111000
>
>Most random number generators return values in the
>interval 0 <= r < 1 that are uniformly spaced in that
>interval and are equiprobable.

Ideally, yes, but in practice, they are pseudo (note, pseudo)
and aren't perfect.

> Both of those last properties
>are very desirable. Your "solution"

It was a suggestion. Please note the wording:
"You could try multiplying your random number by
"NEAREST(1.0, 2.0)
"and, just for safety, checking that the product is
"not greater than 1.0. If it is, replace it with 1.0."

There are many options available to the OP, including
adapting and/or using one of the numerous PNRGs
available in computer science literature and on the internet.

> will not return values
>on the interval 0 <= r <= 1 that are uniformly spaced.

I am sure that everyone is aware of that. However,
virtually all are [uniformly spaced].

>For example, on IEEE single precision, you get 2^24
>values in the interval 0 <= r < 1 and the spacing between
>the possible results is 1/2^24.

Do you really think that anyone might notice the one in
some 16,000,000?

In a typical use, the value might never be generated anyway.

BTW, I have been writing pseudo-random number
generators and using PRNGs for 30+ years, so the
remainder is

<snipped>

>--
>J. Giles


.



Relevant Pages

  • Re: Random numbers
    ... But even ignoring that, if you were trying to create generators ... which produce uniformly distributed (pseudo) random numbers, ...
    (sci.math)
  • Re: Random Number Generation -----> Hardware or Software?
    ... > Ada has some requirements on the built-in (pseudo) random number ... But those requirements still don't get you a PRNG that you'd want to ... Offhand I don't recall whether the simple linear congruential generators ...
    (comp.arch.embedded)