Thread: Non repeat random number generator

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    1

    Non repeat random number generator

    Hi everyone, well i'm new to c programming..basically i need some help of how to figure out a non repeat random number generator...i got an assignment on that..here the question..

    Six numbers between 1 and 40 inclusive are generated at random.
    If a number has been generated it is not generated a second time.

    Each time the game is played a completely new and random set of six numbers between 1 and 40 inclusive are generated.


    A player can bet any six numbers between 1 and 40 inclusive.





    The cost for each bet is $20. A player can bet as many times as he wishes for each
    draw. If the player gets all the six numbers correct (the order is not important) he wins the
    jackpot.
    If more than one player wins the six correct numbers the jackpot is shared equally among
    them. The program should be able to record all the players, their bet and the total bet. For
    five, four and three correct (again order is not important) betting consolation prizes are
    awarded. Obviously as the number of correct numbers decreases the number of potential
    winners increases and the prizes decrease also.

    The lecturer told to make use of function..but how and where to start..:S:S

    i know there are many topic on random number on this forum...any reference would be appreciate...help me plz...thx

    p.s sorry for the bad english..:P:P
    Last edited by theworldofdota; 10-14-2011 at 11:55 AM.

  2. #2
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Just use the normal random number generator. Keep generating new numbers until you have 6 unique ones, by comparing the just generated number to the ones generated previously.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Or alternatively, fill an array with the numbers from 1 to 40, perform a random shuffle and then just take the first six numbers. You'll need to make sure you use a proper random shuffling technique.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need a random number generator thats not compleatly random
    By thedodgeruk in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2011, 06:48 AM
  2. random number generator
    By morrissey999 in forum C Programming
    Replies: 18
    Last Post: 05-01-2011, 04:53 PM
  3. Making card generator random and not repeat cards
    By rfoor in forum C++ Programming
    Replies: 3
    Last Post: 12-12-2010, 12:31 PM
  4. help with random number generator
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-27-2003, 03:46 PM
  5. Random number generator
    By Caze in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2002, 08:10 AM