0

I'm trying to generate a random float number between 0 and 1.

0.0f + rand() % 1.0f;

But I get the following error after I compile with GCC:

error: invalid operands to binary % (have ‘int’ and ‘float’)
LearningProcess
  • 607
  • 1
  • 8
  • 29
bob smith
  • 63
  • 8
  • I'm pretty sure modular arithmetic only works on integers because any other kind of number can just use regular division and mod loses its purpose. – Arc676 Oct 31 '15 at 04:20
  • 1
    Thanks for the help guys, this solved my question.(float)rand() / (float)(RAND_MAX / 1.0f) – bob smith Oct 31 '15 at 04:23

0 Answers0