lizi_n
02-07-2008, 04:56 PM
I need to randomly generate an equal number of +1s and -1s. I have used call random_number and then made every number >0.5=1 and any number<0.5=-1. This is in a do loop from 1..n but I don't know how to ensure I have the same amount of 1's as -1's. any help would be greatly appreciated!!
davekw7x
02-08-2008, 11:29 PM
... know how to ensure I have the same amount of 1's as -1's...
If you want to know whether there are an equal number of +1's and -1's among the numbers, couldn't you just add up all of the numbers and see if the result is zero?
That doesn't sound very "random" to me, but I am not sure what you are getting at. I mean, if you are generating the numbers "randomly," how the heck can could you expect to "ensure" an exactly equal number of values in the two particular ranges?
Regards,
Dave
davekw7x
02-09-2008, 09:36 AM
... but I am not sure what you are getting at....
Maybe I shouldn't have answered without thinking about what I think you want. Sorry.
Consider:
1. Create an array with +1 values in the first half and -1 values in the other half. Just 1,1,1,...,1,-1,-1,-1...,-1
2. Use a random number generator to perform a "random shuffle" of the elements in the array.
Regards,
Dave