How can I make it so this rand gives out numbers that are increments of 50
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. ThanksCode:int wa = (rand()%700 + 300);
How can I make it so this rand gives out numbers that are increments of 50
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. ThanksCode:int wa = (rand()%700 + 300);
Basiclly there are 15 incraments of 50 between 300 and 1000.Code:wa = ( (rand % 15) * 50) + 300;
Edit: 15 incraments include 300 and 1000.
Last edited by Thantos; 08-07-2003 at 08:52 PM.
Thanks... didn't think about it like that... make it work the way you want to right
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:
Display is optimized for multiples of 16 character (or 80 character) widthCode:#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; }
Last edited by WaltP; 08-07-2003 at 08:00 PM.
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
So we should stop propogating the fallacy....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.
... and only mention this fact when the process requires absolute randomization. Normal programming should have no problem with the standard randomization.> 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.
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
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().