pseudo-random 
Author Message
 pseudo-random

hello world --

i fully understand how to use the rand(), srand(), and randomize()
functions. however, i would like to enquire of the gurus out there if
they know exactly how these functions work. specifically, i'm using
borland turbo c/c++ 3.0 for dos. so how *does* the rand() function
actually work? what's the algorithm that is used to implement it? does
this vary from compiler to compiler and from platform to platform?

-- ben



Fri, 26 Mar 1999 03:00:00 GMT  
 pseudo-random


Quote:

>hello world --

>i fully understand how to use the rand(), srand(), and randomize()
>functions. however, i would like to enquire of the gurus out there if
>they know exactly how these functions work. specifically, i'm using
>borland turbo c/c++ 3.0 for dos. so how *does* the rand() function
>actually work? what's the algorithm that is used to implement it? does
>this vary from compiler to compiler and from platform to platform?

Volume II (?) ("Seminumerical Algorithms") of Donald Kniuth's classic "The Art
of Computer Programming" will tell you all this and more.

--
James Youngman       VG Gas Analysis Systems |The trouble with the rat-race
 Before sending advertising material, read   |is, even if you win, you're
http://www.law.cornell.edu/uscode/47/227.html|still a rat.



Sat, 27 Mar 1999 03:00:00 GMT  
 pseudo-random

Quote:


> >hello world --

> >i fully understand how to use the rand(), srand(), and randomize()
> >functions. however, i would like to enquire of the gurus out there if
> >they know exactly how these functions work. specifically, i'm using
> >borland turbo c/c++ 3.0 for dos. so how *does* the rand() function
> >actually work? what's the algorithm that is used to implement it? does
> >this vary from compiler to compiler and from platform to platform?

> Volume II (?) ("Seminumerical Algorithms") of Donald Kniuth's classic "The Art
> of Computer Programming" will tell you all this and more.

Knuth gives you the theory of pseudo-random number generation. Actual
implementations will vary from one vendor to the next.


Sat, 27 Mar 1999 03:00:00 GMT  
 pseudo-random

Quote:

>hello world --
>i fully understand how to use the rand(), srand(), and randomize()
>functions.

randomize() is not a function from the standard C library, and there
are completely different functions trading under that name in popular
implementations of the C programming language.

Quote:
>however, i would like to enquire of the gurus out there if
>they know exactly how these functions work.

If you really need a "guru", comp.lang.c is probably the wrong place
to look. Caves in northern India might be a better place to start
your quest.

Quote:
>specifically, i'm using
>borland turbo c/c++ 3.0 for dos. so how *does* the rand() function
>actually work?

Have you tried to consult you manual, or, if you do not find anything
in there, Borland's customer support.

Quote:
>what's the algorithm that is used to implement it? does
>this vary from compiler to compiler and from platform to platform?

It differs from one implementation of the standard C library to the
other. So, linking a program compiled with the same compiler on the
same platform against different builds of the standard C library
may invoke different implementations of rand() and srand()

There are lots of different possible implementations of pseudo random
number generators. None of them will generate a random sequence, i.e.
a sequence that is not computable, but shows relative frequencies
converging with the length of a subsequence on every subsequence.

Kurt

--
| Kurt Watzka                             Phone : +49-89-2180-6254



Sat, 27 Mar 1999 03:00:00 GMT  
 pseudo-random

Quote:

>i fully understand how to use the rand(), srand(), and randomize()
>functions. however, i would like to enquire of the gurus out there if
>they know exactly how these functions work. specifically, i'm using
>borland turbo c/c++ 3.0 for dos. so how *does* the rand() function
>actually work? what's the algorithm that is used to implement it? does
>this vary from compiler to compiler and from platform to platform?

For a thorough discussion of random functions, look in any of a number of
books, including Knuth's _Art of Computer Programming_, vol. 2(?). (Other
people will recommend other books, but the point is that there are an
infinite number of ways to implement a pseudo-random number generator).

That said, the exact implementation in rand() and srand() is up to the
creators of the library being used. It varies from compiler to compiler,
and details often vary from release to release, let alone from platform
to platform.

MOST compilers where I've had reason to look at how rand() was
implemented used a simple linear-congruential generator. Some of these
were not even very good ones, but they have the advantage of being easy
to implement (if poorly) and somewhat fast-running. For srand() in those
cases, you merely set the current value of the generator's seed to the
number passed.

Another common generator used makes the assumption that calls to rand()
won't come in quick succession: it examines the system clock to get a
number that's unpredictable.

And, of course, the best choice ofpseudo-random number generator depends
on the job at hand.

  Bob   (who tends to use a linear-feedback-shift generator when he has
to implement such a thing)

--
  Bob           One good thing about being wrong is the joy it brings to others



Sat, 27 Mar 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Any good methods for generating pseudo random integer?

2. Pseudo random number generator

3. simple pseudo random generator

4. Help! Pseudo Random Function Generator in C

5. pseudo-random numbers

6. Yet another pseudo-random number generator

7. Pseudo-random number generators

8. Pseudo-Random Number Generater

9. More pseudo random numbers?

10. BBS pseudorandom number generator

11. Pseudorandom Number Generator Information Needed

12. Pseudorandom numbers with clock()

 

 
Powered by phpBB® Forum Software