How can i generate 128 random numbers on an interval of -64 to 64?
thanks.
How can i generate 128 random numbers on an interval of -64 to 64?
thanks.
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
perfect thanks...
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.