Thread: PseudoRandom Class Help??????

  1. #1

    Question PseudoRandom Class Help??????

    Need immediate help with this problem..............
    Please someone, anyone!!!!!!

    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.

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    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,


    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User
    Join Date
    Aug 2002
    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.
    Best Regards,


  4. #4
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    >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.

  5. #5
    Registered User
    Join Date
    Aug 2002
    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.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM