This is a discussion on Fix Please within the C++ Programming forums, part of the General Programming Boards category; Usually, it means you give the computer a start number, then it applies an algorithm on that number to produce ...

1. Usually, it means you give the computer a start number, then it applies an algorithm on that number to produce "random" numbers.
Of course, there are "random" generators and not-so-random generators (not-so-random generators may produce the exact same sequence of numbers from the same seed).

2. Well actually, you can get a pseudorandom number algorithmically by multiplying a seed with a constant and taking the mod of another constant. I'll show you one:
Code:
```int seed=1;

void LCGseed (unsigned int _seed)
{
int i, h=1;
unsigned char *p=&_seed;
for (i=0; i < sizeof _seed; h++) {
h = h>>24 * h<<4 ^ p[i];
}
seed=h;
}

int LCGrand (void)
{
return seed*=16807UL &#37; 2147483647UL;
}```
The algorithm, when called several times, naturally produces a series called a period. Large periods are good, but more important is the factor of unpredictability. We shouldn't rely on the default seed because that would make the generator more predictable and the result very deterministic. The seed is actually the last number the generator returned. If you're using the generator for the first time, it would be a good idea to set the seed somewhere in the period to start off from other than the default value, using a unique source, like the time.

The example is actually a great deal similar to the rand/srand generator provided by C++, and that's not a very good one. But it's a place to start. You can learn more about PRNGs on the web.

3. Originally Posted by Nestor
Listem men, i started programing yesterday....well today 1 am, i havn't gotten as far as a random numbers generator:P but if you are bored you can explain how it can be a random number generator if the computer can't think for itself?

random isn't really random?

for through understanding, read till the last page.

5. It's got an extra http// in it by mistake. Delete that in the address bar and you can follow it.

6. ## go back

Go back to tutorials. In my opinion Cprogramming tutorials suck so find a better online tutorial, buy a book, or just stop posting such stupid threads

7. And you'd better learn to control that attitude of yours, because frankly, it sucks.

8. Me? Was that to me?

9. No, to lruc.
Nothing wrong with you, Nestor. Don't worry.

Page 2 of 2 First 12