# Thread: How to correctly implement random decimals?

1. ## How to correctly implement random decimals?

I've been experimenting with this method for the last five minutes and it hasn't properly produced what exactly I want. I want a program that outputs 10 random decimal numbers. All of the decimal numbers should be lower than 2.00, meaning, that some of the numbers that actually get placed on screen(output) should be like:

1.91
0.19
0.45
etc.

Well, enough talking. Let me paste what I've done. I hope the next person that post can come up with a quick, peaceful(not bashful) solution.

Code:
```#include <iostream>
#include <stdlib.h>
#include <time.h>

int main()
{
double number;

for(int i=0; i<=10; i++)
{
number= (rand() % 1) + ( (rand() % 99) * 0.10);
cout << number << endl;
}

cin.get();
return 0;
}```

2. >>decimal integers

an integer is a whole number, can't be decimal, thats a double or float.

3. Some advice to future responders. If you have some minor to say just PM me. The whole point of me posting this topic is to get this problem resolve. Not to better my english.

Note: I was in a rush when I was typing that. Notice how I edit my post like 2 times already.

4. isnt it

(rand () % (high - low + 1) ) + low;
so if you use decimal...never tried..sorry cant compile right now i just reformat hard drive.....going to reinstall visual studio 6.0 ent in a few mins

5. Some advice to future responders. If you have some minor to say just PM me. The whole point of me posting this topic is to get this problem resolve. Not to better my english.
note to authors...don't wanna hear it, don't post it.

6. Any number modulus one is zero. If you want 0 or 1 you need to modulus by 2. Also, if you modulus 99, then 99 will not be a possible answer. And last, if you multiply by .1 then your range is from .1 to 10 instead of .01 to 1. I think what you need is:

number= (rand() % 2) + ( (rand() % 100) * 0.01);

OR

number=(rand()%200)*.01;