pick_dist.c 1021 B

12345678910111213141516171819202122232425262728293031
  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 "local_proto.h"
  21. int pick_dist(int u)
  22. {
  23. int v;
  24. v = (int)((u + 0.99999999999) * rand() / INT_MAX);
  25. u = (int)((v + 0.99999999999) * rand() / INT_MAX);
  26. return ((int)((u + 0.99999999999) * rand() / INT_MAX)); /*4th for a test */
  27. }