# Random Number Generation-Increments

• 04-12-2010
CPPN0OB
Random Number Generation-Increments
Hi, I'm trying to generate a random number between 50 and 1000(inclusive) in increment of 50.

I'm using the libraries

Code:

``` #include <ctime> #include <cstdlb>```
Here's the actually code I'm using.... I'm calling this function inside of a loop in the main function. I'm getting the correct numbers but I am occasionally getting 0 and the same number often repeats itself.

Code:

``` int getspin() {         srand(time(NULL));         int x;         x = (rand()%1001 +50)/100 *50;         return x;  }```
• 04-12-2010
laserlight
You may find it easier to generate numbers in the range [1,20], and then multiply by 50.
• 04-12-2010
tabstop
The range of what you have is anywhere from 0 to 500, it would look like. And if you couldn't get repeats, it wouldn't be a random number, would it?

There are twenty possible outcomes. It's easy to get rand between 0 and 19; can you think of a way to do
0 -> 50
1 -> 100
2 -> 150
3 -> 200
.
.
.
18 -> 950
19 -> 1000?