# PseudoRandom Class Help??????

• 10-14-2002
funny0ne
PseudoRandom Class Help??????
Need immediate help with this problem..............

Problem Specification

In this assignment, you are to design and implement a class that can generate a sequence of pseudorandom integers, which is a sequence that appears random in many ways. The approach uses the linear congruence method, explained as follows.
The linear congruence method starts with a number called the seed. In addition to the seed, three other numbers are used in the linear congruence method, called the multiplier, the increment, and the modulus. The formula for generating a
sequence of pseudorandom numbers is quite simple. The first number is:

(multiplier * seed + increment) % modulus

This formula uses C++ % (modulus) operator, which computes the remainder from an integer division.

Each time a new random number is computed, the value of the seed is changed to that new number. For example, we could implement a pseudorandom number generator with the following parameters:

multiplier = 40
increment = 725
modulus = 729

If we choose the seed to be 1, then the sequence of numbers will proceed as shown here:

First number = (40 * 1 + 725) % 729 = 36
and 36 becomes the new seed.

Second number = (40 * 36 + 725) % 729 = 707
and 707 becomes the new seed.

Next number = (40 * 707 + 725) % 729 = 574
and 574 becomes the new seed and so on.

These particular values for multiplier, increment, and modulus happen to be good choices. The pattern generated will not repeat until 729 different numbers have been produced. Other
choices for the contants might not be so good.

For This Project Design and implement a class that can generate a pseudorandom sequence in the manner described above. The initial seed, multiplier, increment and modulus
should all be parameters of the constructor. There should also be a member function to permit the seed to be changed, and a member function to generate and return the next number
in the pseudorandom sequence.
• 10-14-2002
kermi3
Please don't ask people to do all your work for you, See the announcement on Homework at the top of the forum to see what is acceptable ro PM. Basically people are happy to help, but they're not going to do it all for you. Show us what you've got, show your code (using code tags), or where you're confused and someone will be happy to help you I'm sure. Feel free to PM me with any questions.

Good Luck,

Kermi3
• 10-14-2002
bonkey
What you describe here will not generate random numbers. In fact if you always start with a seed of 1 then generate 100 numbers. If you start it again, you will generate the same 100 numbers. There needs to be something that will change things up some. Normally people will insert the current time into the equation. This is ok for most cases. If you need to be more random then you need something with more randomness, like time and cpu idle time or something like that.
• 10-14-2002
Davros
>What you describe here will not generate random numbers.

No it isn't random, it is deterministic, but appears random. Hence, 'psuedo random'. But I thought we all understood that.

>Normally people will insert the current time into the equation.

In fact, what you actually do is to seed it with time.

Ability to set the seed is important. For many applications you want the repeatability.

To generate true random numbers, hardware is needed, which rely on quantum effects (i.e. radioactive decay). You can actually buy random generator modules for around \$10 - \$20, they normally plug into the serial port.
• 10-14-2002
bonkey
Quote:

Originally posted by Davros
>

No it isn't random, it is deterministic, but appears random. Hence, 'psuedo random'. But I thought we all understood that.

In point of fact all random numbers generated by a computer are psuedo-random. But, I thaught we all understood that.

My point was that generating the precise string of numbers over and over again was probably not his desired result. If it is more power to him.

More to the point, I do not post here to be flamed. I post to be helpfull. If there is some error in what I am saying, that is one thing, but to attack what I am saying not based on actual errors, but instead on your perception of my knowledge, I find unacceptable.

If you want to prove that you are some computer genius, yay for you. You are not the best member on this site. Do you want this to be the norm? You post and then your posts are picked apart? Picked apart not just for errors, but for style? This is a great site to get help and info, which is what he wanted. It won't stay a great site if all our responses begin to be flamed.

I just sent a coworker to this site on Friday, specifically stating that on this site you don't have to worry about trolls and flamers. I guess I may have to give him an update.
• 10-14-2002
master5001
I would first like to thank you for going into painstaking detail into the issue ;) I'm not trying to flame you but I think you could have stopped the post after the first sentence and we would have all understood.

I'm not going to do you homeword assignment for you. If I did then I learned something (if I didn't already know it) not you. But I can tell you about a particularly interesting algorithm. It is called the
Mersenne Twister' random number generator and it is an excelent way of generation random numbers. The thing that sets this function apart from the others is that it uses absolutely no divisions and no moduluses.

But if you do use this algorithm for your homework you would be cheating and if you don't give credit to the author then you would be stealing too. You may want to look at it just to see how you can make your own.