Generating random numbers

Nov 19, 2014 at 4:43pm
I keep getting invalid operands to binary expression ('double' and 'double').
I tried to solve it myself, but no cigar.
What I am trying to do is populate an array with random numbers form 0.01 to 10.99.
Please help me with only the rand function.



 
  price[i]= rand() %  (10.99) +( 0.01);
Nov 19, 2014 at 4:51pm
try double j = (double)(rand()%1099+1)/100;. Your code doesn't work because % only works with int divisors.
Nov 19, 2014 at 7:35pm
hey i don't know if this is solved yet but i like to use

this will give you between 0 and 4

float tmp = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / 4));
Nov 21, 2014 at 1:08am
Thank you guys both for your help it helped me solve it.
Topic archived. No new replies allowed.