# Thread: Making some random numbers..

1. ## Making some random numbers..

Hi, I'm trying to generate the same random numbers(i.e. no srand() function needed) but I can't seem to figure out how to get it to work for the range I am in. I want it to be in the range of .5 to 1. Someone hinted that I divide by the constant RAND_MAX and do some other things, but that really seems to do nothing except produce 0. Any help will be nice. sorry for the noob question. And YES, I READ THE FAQ!

I tried this and it doesn't seem to work when I'd think that it would. It just gives me 0.
Code:
`((rand()%50) / 100) + .5`

2. Oh dumb me for forgetting to realize rand returns an int. Thanks Salem.

3. Random numbers huh? What I usually do is:
Code:
```#include <iostream>
#include <stdlib.h>
#include <ctime.h>
using namespace std;

int main()
{
srand(time(0));
cout << (rand()%19)+1 << endl; // random number between 1 and 20
cout << (rand()%99)+1 << endl; // random number between 1 and 100
cout << (rand()%10)+10 << endl; // random number between 10 and 20
return 0;
}```
Hope this helps

4. >>cout << (rand()%19)+1 << endl; // random number between 1 and 20<<
This is incorrect.
rand()%19 will get you a number between 0 and 18, adding 1 will make it 1 to 19 (not 20 as your comment states).

5. Oh, (rand()%20)+1 then.. that should do it..