random fill generator

Discussion in 'Programmer's Corner' started by stevy123, Mar 1, 2008.

  1. stevy123

    Thread Starter Active Member

    Nov 19, 2007
    61
    0
    Hi All

    Just wondering could anyone help me with a little code i am trying to write.

    I have 6 numbers i.e 100, 200, 300, 300, 500, 600 and want to randomly allocate them into 6 set locations. I am usign c++ so is there any easy way of doing this?

    Then how do i check to see which number is stored were?

    Many thanks
    Steve
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
  3. stevy123

    Thread Starter Active Member

    Nov 19, 2007
    61
    0
    Hi beenthere thanks for your response, but as i have said in the question i dotn want it just to be random numbers i want it to b 1 of the 6 selected numbers to be randomly assigned into 1 of the 6 locations.

    Anyone any ideas?

    Regards
    Steve
     
  4. veritas

    Active Member

    Feb 7, 2008
    167
    0
    Just use a random number generator function, like one that produces a value from 0 to 1, and then use logic to partition the results into your 6 bins. e.g. 0-0.166 => 100, 0.167-0.333 => 200, etc.

    If the random number has already been assigned, generate a different one.
     
  5. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    Put the 6 values into a 6 value wide array,
    use the random number from 0-5 to generate a pointer to the array.
     
Loading...