(drand48() * LIMIT)

Does the above code in 'generate.c' file of pset3 mean that drand48 generates random numbers upto the value defined in LIMIT?

E.g -

#define LIMITS 234


In this case with the above code will drand48 generate numbers from 0 to 234?


No, drand48() * LIMIT will not generate number up to 234, it will instead generate 234 different random numbers of size up to INT_MAX. That said you didn't post the full line in question, so I'm not able to tell what exactly is happening.

  • Can you now answer the question ? Nov 19 '16 at 15:26
  • The same will happen, drand48() * LIMIT will not generate numbers up to 234, instead it will generate 234 different numbers. What I meant with not being able to tell exactly what is happening is that the generated numbers aren't being stored or used for anything.
    – kluvin
    Nov 19 '16 at 15:33
  • And please can you explain what is INT_MAX? Nov 19 '16 at 15:33
  • INT_MAX is a constant defined in limits.h which is the maximum value that can be held by an integer before an overflow, in the case of CS50 it is just over two billion, but again that will vary between implementations. msdn.microsoft.com/en-us/library/296az74e.aspx
    – kluvin
    Nov 19 '16 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .