Computer Science Canada Randomizing Integers and eliminating last picked |
Author: | Joe Keller [ Sat Jan 21, 2012 1:19 pm ] | ||
Post subject: | Randomizing Integers and eliminating last picked | ||
What is it you are trying to achieve? So I was wondering how you randomized numbers, for example 1 to 6, and if one of them were chosen last time by the generater, don't let it be chosen again. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
|
Author: | Beastinonyou [ Sat Jan 21, 2012 1:46 pm ] | ||
Post subject: | Re: Randomizing Integers and eliminating last picked | ||
Well, considering you already understand how to randomize integers, you just need a way to prevent that integer from being picked again. A simple way to do this is using an array of boolean:
|
Author: | Joe Keller [ Sat Jan 21, 2012 1:49 pm ] |
Post subject: | RE:Randomizing Integers and eliminating last picked |
Thank you, I never used arrays before Ill put them in to my program in a bit and tell you how it went |
Author: | Tony [ Sat Jan 21, 2012 1:54 pm ] |
Post subject: | RE:Randomizing Integers and eliminating last picked |
it's important to recognize that with this method, picking the last element would just be a loop with 1/6 chance of exiting. This gets prohibitively slow when you are picking elements from a larger set. |