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?
randomizing set values in an array
Collapse
X
-
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.)Originally posted by ag203We'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? -
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.Originally posted by ag203how would I do this code wise?
liek I understand the new array but I need help with the moving slots
Check this out, it will get you started:
http://www.daniweb.com/techtalkforums/thread1769.htmlComment
Comment