# How to modify this rand

This is a discussion on How to modify this rand within the C Programming forums, part of the General Programming Boards category; How can I make it so this rand gives out numbers that are increments of 50 Code: int wa = ...

1. ## How to modify this rand

How can I make it so this rand gives out numbers that are increments of 50

Code:
`int wa = (rand()%700 + 300);`
I already have it so the numbers are between 300-1000 just tried about everything to get it to work but can't seem how too. Thanks

2. Code:
`wa = ( (rand % 15) * 50) + 300;`
Basiclly there are 15 incraments of 50 between 300 and 1000.

Edit: 15 incraments include 300 and 1000.

3. Thanks... didn't think about it like that... make it work the way you want to right

4. The only problem with that, according to this, is that the low order bits aren't very random. You might want to adapt what they have on that site.

(btw, that link was found here)

5. Originally posted by blackrat364
The only problem with that, according to this, is that the low order bits aren't very random. You might want to adapt what they have on that site.

(btw, that link was found here)
I haven't seen evidence of this. I would like to see their proof. After all, 80% of the programmers use random numbers Statistics are soooo useful.

As a test, try this program to see if randomization is not accurate:
Code:
```#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,j;
for (i=0; i<500; i++)
{
j = rand();
printf(" %04X  %02X  %02X   ", j, j >> 8, j & 0x0FF);
}
return 0;
}```
Display is optimized for multiples of 16 character (or 80 character) width

6. Originally posted by Salem
> I haven't seen evidence of this. I would like to see their proof
It was only literally true in some very old implementations.
Standard library rand() generators are typically linear congruential generators (LCG) (like in Visual C++ 6), but they avoid this FAQ issue by returning the high order bits.
So we should stop propogating the fallacy....

> Statistics are soooo useful.
Indeed, as is cryptography.
The standard library rand() is useless for serious use in both fields.
This shows how badly a standard LCG-based rand() performs statistically.
... and only mention this fact when the process requires absolute randomization. Normal programming should have no problem with the standard randomization.

7. If you understand why rand() is insufficiently random, then you are probably using a random number generator that suits your needs... for everything else there is rand().