rand1.c 693 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdlib.h>
  2. #include <grass/gis.h>
  3. #include <grass/gmath.h>
  4. /*!
  5. * \fn float G_math_rand (int seed)
  6. *
  7. * \brief Random Number Generator (Uniform)
  8. *
  9. * Random number generator (Uniform Derivatives 0.0 -> 1.0)
  10. *
  11. * \param[in] seed
  12. * \return float
  13. */
  14. float G_math_rand(void)
  15. {
  16. return G_drand48();
  17. }
  18. /*!
  19. * \brief Seed the pseudo-random number generator
  20. *
  21. * \param seedval 32-bit integer used to seed the PRNG
  22. */
  23. void G_math_srand(int seed)
  24. {
  25. G_srand48(seed);
  26. }
  27. /*!
  28. * \brief Seed the pseudo-random number generator from the time and PID
  29. *
  30. * \return generated seed value passed to G_srand48()
  31. */
  32. int G_math_srand_auto(void)
  33. {
  34. return (int) G_srand48_auto();
  35. }