pick_dist.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /******************************************************************************
  2. *
  3. * pick_dist.c inverse square distance distributed probability generator
  4. *
  5. * Usage: pick_dist (maxnumber)
  6. *
  7. * Notes: prob_invsqr() generates a decreasing probability distribution
  8. * outward in an inverse square rate. It use three consecutive random number
  9. * generator:
  10. * applying it once gets an UNIFORM distribution in the range of 0-max_num;
  11. * doing it twice gets a SIMPLE INVERSE distribuion in that range;
  12. * doing three times gets a INVERSE SQUARE distribution.
  13. *
  14. * Author: Jianping Xu, Rutgers University
  15. * Date: 06/11/1994
  16. ******************************************************************************/
  17. #include <stdlib.h>
  18. #include <limits.h>
  19. #include <math.h>
  20. #include <grass/gis.h>
  21. #include "local_proto.h"
  22. /**
  23. * @brief Picks one possible distance value from range 0, u
  24. * @param u maximum pontential distance
  25. * @return value in range 0, u
  26. */
  27. int pick_dist(int u)
  28. {
  29. int v;
  30. v = (int)((u + 0.99999999999) * G_drand48());
  31. u = (int)((v + 0.99999999999) * G_drand48());
  32. return ((int)((u + 0.99999999999) * G_drand48())); /*4th for a test */
  33. }