-
October 11th, 2010, 06:38 PM
#1
Random Arrays
Hello,
I am working on a project for fun. What I am trying to do is create a C# version of the game Deal or No Deal.
Currently, I am struggling with the concept of the briefcases. What I would like to do is create an array of size 26 (there are 26 total briefcases) with values between $0.01 and 1M (just like on the game show).
This way, the case number can be the index of the array element and the values can be any value between $0.01 and 1M.
So, my question is: Is there a way to create an array that fills randomly with a predefined set of values?
Or does anyone think it would be easier to create a "briefcase" object with attribute of number and value?
Thanks for any advice,
Bill
-
October 12th, 2010, 12:59 AM
#2
Re: Random Arrays
Put the values in the array in order.
Then write a loop which executes 1 zillion times. Each time around the loop pick 2 random numbers between 0 to 25 inclusive and swap the array values at those index's.
A bit like shuffling cards...
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
-
October 12th, 2010, 10:34 AM
#3
Re: Random Arrays
You don't need to swap numbers millions of times. The algorithm you are looking for is called Fisher–Yates shuffle and is quite efficient (check for the modern algorithm).
Hope it helps
JeffB
-
October 13th, 2010, 03:41 AM
#4
Re: Random Arrays
ok, a zillion was a bit of an exagg I think the way I suggested maps more to the real world than FYS.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|