Re: random numbers' function



On Jan 22, 6:35 am, gw7...@xxxxxxx wrote:
On 22 Jan, 10:47, "[Jongware]" <so...@xxxxxxxxxxx> wrote:





robertwess...@xxxxxxxxx wrote:
On Jan 21, 8:26 pm, CBFalconer <cbfalco...@xxxxxxxxx> wrote:
Tagore wrote:

How to make a function to generate random numbers between 1 to 7 using
another function which generate random numbers between 1 to 5?
Since 5 and 7 are prime, they are also mutually prime.  Generate 7
calls to the 1..5 function, and add the results.  Divide that sum
by 5.  The result will be in the 1 to 5 range.

If you can do seven calls to the rand5 function, compute:

t = rand5()*(5**6)+rand5*(5**5)*rand5()*(5**4)+rand5*(5**3)*rand5()*
(5**2)+rand5*(5**1)*rand5()*(5**0);

And then generate five evenly distributed random numbers by repeatedly
dividing by seven and outputting the remainder.  No wasted input bits,
either.

(Note: assumes that rand5() returns 0..4, and that the output is 0..6
- obvious adjustments required for base 1 inputs and/or outputs).

I've assumed the same thing, and came to exactly the same conclusion.
Since 5 and 7 have no common divider, you need to call the RNG 7 times,
to ensure a perfectly even distribution (at least, with roughly the same
distribution the RNG provides for 5 random numbers). Any 'clipping'
might distort the outcome.

The inverse is also true!

"How to make a function to generate random numbers between 1 to 5 using
another function which generate random numbers between 1 to 7?"

To ensure the same distribution (and, as James Dow Allen further
specifies, a terminating program), one should call the RNG 5 times, not
x times-until-less-than-5.

Chuck, Robert, Jongware - I'm afraid I think you are all wrong, in
that there is no way to produce a perfect distribution.

If you call the generator n times, then there are 5^n equally likely
possible outcomes. We want to make exactly 1/7 of these map onto an
output of 1 - which is impossible as 5^n is not a multiple of 7.
Calling the random number generator fewer times in certain
circumstances won't help, as this is equivalent to always calling it n
times and sometimes ignoring the later results. If the algorithm has a
maximum number of times to call the generator, then the outcome must
be skewed.


Absolutely correct. I was thinking of a different relationship, and
just pooched it by applying it to this problem.
.



Relevant Pages

  • Re: Is Itos Lemma correct?
    ... What algorithm did you use for your random number generator? ... Here's the original location and distribution of Mr. Steve Park: ... It's characterized as "a very accurate approximation of the normal idf". ... could lead to a loop in the RNG. ...
    (sci.math)
  • Re: random numbers function
    ... dividing by seven and outputting the remainder. ... Since 5 and 7 have no common divider, you need to call the RNG 7 times, ... distribution the RNG provides for 5 random numbers). ... Calling the random number generator fewer times in certain ...
    (comp.programming)
  • Re: issues with statistical test suite from http://csrc.nist.gov/rng/
    ... A distribution, or data set, is symmetric if it looks the ... >> A generator is bad when it fails a test that has a good mathematical ... The most common criteria are lack of correlation and even ... Since some of the best minds in mathematics can't come up with ...
    (sci.crypt)
  • Re: issues with statistical test suite from http://csrc.nist.gov/rng/
    ... >> ses is the standard error of skewness. ... >distribution differs from the expected one. ... >Unfortunately I can't know if a generator under test is good or bad if it ... Kurtosis could be ...
    (sci.crypt)
  • Re: question on entity generation/termination
    ... use the event based random number generator block. ... be the distribution parameters, and using those you can generate random ... The EML block is a time-based block ... The parameter of the event-based random number ...
    (comp.soft-sys.matlab)