How can i generate 128 random numbers on an interval of -64 to 64?

thanks.

Printable View

- 11-30-2006jarheadhalorand()
How can i generate 128 random numbers on an interval of -64 to 64?

thanks. - 11-30-2006laserlight
Generate a random number (integer?) in the interval [0, 128], and repeat another 127 times. To make each number be in the range [-64, 64], just subtract 64 from each number generated.

- 11-30-2006jarheadhalo
perfect thanks...

- 11-30-2006Daved
Is it ok to have repeats, or must the numbers all be unique?

If they all have to be unique, then what you want to do is create an array with all the numbers in it (there are 129 numbers between and including -64 and 64, so you'd have to have an array of size 129). Then randomly shuffle the array. The best and easiest way to do that is to call the random_shuffle algorithm. If you aren't allowed to use that because of class requirements or something, you can mimic the algorithm. Be careful, though, because it is easy to get the algorithm slightly wrong and really throw off the random distribution.