uniform random distribution

From: aegis (aegis_at_mad.scientist.com)
Date: 01/30/05


Date: 30 Jan 2005 13:18:11 -0800

is there any trickery that can be done
with rand() so that it generates a uniformly
distributed sequence?

Suppose that I want any thing in the range
m..n (inclusive) to be generated such that
I never have a recurrence of a number.

I could build a table I suppose as I call
rand and any number in that table already
can be ignored. So I can sit and call rand
until I get the desired number that is not yet
in the list.

So if I want (inclusive) 0..3
then imagine rand() % (3 + 1) working as desired.

I consider the use of a table to keep track to be
a pretty idiotic approach though. Anyone have
another way of doing it, up their sleeve?

--
aegis


Relevant Pages

  • Re: uniform random distribution
    ... aegis wrote: ... > is there any trickery that can be done ... > with rand() so that it generates a uniformly ...
    (comp.lang.c)
  • Re: uniform random distribution
    ... > is there any trickery that can be done ... > with rand() so that it generates a uniformly ... you need a new generator and have to rebuild your ...
    (comp.lang.c)
  • Re: uniform random distribution
    ... >is there any trickery that can be done ... >with rand() so that it generates a uniformly ... Use the shuffled array as the source ...
    (comp.lang.c)
  • Re: uniform random distribution
    ... >> is there any trickery that can be done ... >> with rand() so that it generates a uniformly ... >> distributed sequence? ... the broken "Reply" link at the bottom of the article. ...
    (comp.lang.c)
  • Re: uniform random distribution
    ... aegis wrote: ... > is there any trickery that can be done ... > with rand() so that it generates a uniformly ...
    (comp.lang.c)