common.c 596 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * common.c
  3. * written by Holmes Futrell
  4. * use however you want
  5. */
  6. #include "common.h"
  7. #include "SDL.h"
  8. #include <stdlib.h>
  9. /*
  10. Produces a random int x, min <= x <= max
  11. following a uniform distribution
  12. */
  13. int
  14. randomInt(int min, int max)
  15. {
  16. return min + rand() % (max - min + 1);
  17. }
  18. /*
  19. Produces a random float x, min <= x <= max
  20. following a uniform distribution
  21. */
  22. float
  23. randomFloat(float min, float max)
  24. {
  25. return rand() / (float) RAND_MAX *(max - min) + min;
  26. }
  27. void
  28. fatalError(const char *string)
  29. {
  30. printf("%s: %s\n", string, SDL_GetError());
  31. exit(1);
  32. }