pick_dist.c 1.0 KB

1234567891011121314151617181920212223242526272829303132
  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. int pick_dist(int u)
  23. {
  24. int v;
  25. v = (int)((u + 0.99999999999) * G_drand48());
  26. u = (int)((v + 0.99999999999) * G_drand48());
  27. return ((int)((u + 0.99999999999) * G_drand48())); /*4th for a test */
  28. }