randomizing set values in an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ag203
    New Member
    • Nov 2006
    • 5

    #1

    randomizing set values in an array

    We're writing a program that similates the show deal or no deal. So we have 25 SET values in an array and every time we restart the program those values need to be randomly placed into those twenty-five slots...does anyone know how to do that?
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by ag203
    We're writing a program that similates the show deal or no deal. So we have 25 SET values in an array and every time we restart the program those values need to be randomly placed into those twenty-five slots...does anyone know how to do that?
    Create a new array, initialize them all to a sentinel value, get a random number between 0 and 24, and move the first to that value. If it's not the sentinel, it's been set, get another random value(and check it again...), and to this 24 times, and move the 25th value to the only open spot (this might or might not be longer than waiting to get that last value into the correct spot.)

    Comment

    • ag203
      New Member
      • Nov 2006
      • 5

      #3
      how would I do this code wise?
      liek I understand the new array but I need help with the moving slots

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by ag203
        how would I do this code wise?
        liek I understand the new array but I need help with the moving slots
        Well, that's the easy part - you just move one to another. The tougher part is the random number generator returning a value between 0 and 24 to get that index.

        Check this out, it will get you started:

        http://www.daniweb.com/techtalkforums/thread1769.html

        Comment

        Working...