Hot answers tagged

3 votes
Accepted

implicit declaration of function 'drand48()' is invalid in c99 / generating random numbers

In order to use the function drand48() you need to: #define _XOPEN_SOURCE /* ALWAYS BEFORE the include statement */ #include <stdlib.h> (you don't need to worry about linking, since these ...
user avatar
  • 1,140
1 vote
Accepted

Understanding the generate.c function

You essentially explained it in your question. drand48() returns a random float between 0 and 1. It isn't designed to return a different range, so you then need to expand that range. By multiplying ...
user avatar
  • 63.5k
1 vote
Accepted

Does (drand48() * LIMIT) generates random numbers upto LIMIT?

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 ...
user avatar
  • 1,223
1 vote

pset4 velocity & ball's angle

I think you may need a separate velocity variable for each dimension (e.g., Vx and Vy). I think this will clear up the angle problem.
user avatar
1 vote
Accepted

drand48() Invalid Operands

You can't use modulus operator with doubles. It only works with integers. That is why it says "invalid operands".
user avatar
  • 18.4k

Only top scored, non community-wiki answers of a minimum length are eligible