By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,483 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

randomizing set values in an array

P: 5
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?
Nov 10 '06 #1
Share this Question
Share on Google+
3 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
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.)
Nov 10 '06 #2

P: 5
how would I do this code wise?
liek I understand the new array but I need help with the moving slots
Nov 10 '06 #3

sicarie
Expert Mod 2.5K+
P: 4,677
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
Nov 10 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.