Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

1 line PRNG

Name: Anonymous 2011-05-02 10:59

Name: Anonymous 2011-05-02 11:24

That's not 1-line. One line (and what most libc implementations use, constants from this example are from MSVC) is:

int _seed; // typically this is stored in thread-local-storage instead as a global (if you're going to comment about this comment style: you're considered harmful, otherwise, please ignore this message)
void srand (unsigned int seed) { _seed = seed; }
int rand(void) { return ((_seed=_seed*214013L+2531011L) >> 16)&0x7FFF; }

Constants themselves differ, but X :=(X*RANDMUL+RANDADD) MOD RANDMOD is one of the most common and simplest PRNGs which are uniformly distributed. TAoCP has many pages on it (and comparison with other PRNGs).

Name: Anonymous 2011-05-02 18:48

// comments considered harmful

Name: Anonymous 2011-05-03 0:05

>>3
HARM MY ANUS

Don't change these.
Name: Email:
Entire Thread Thread List