home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / question / 13315 < prev    next >
Encoding:
Text File  |  1992-11-12  |  2.0 KB  |  56 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!utcsri!newsflash.concordia.ca!IRO.UMontreal.CA!CC.UMontreal.CA!gaumondp
  3. From: gaumondp@ERE.UMontreal.CA (Gaumond Pierre)
  4. Subject: Re: Help with generating random numbers
  5. Message-ID: <1992Nov12.212009.8334@cc.umontreal.ca>
  6. Sender: news@cc.umontreal.ca (Administration de Cnews)
  7. Organization: Universite de Montreal
  8. References: <1992Nov12.041243.5542@desire.wright.edu> <1992Nov12.211023.8188@cc.umontreal.ca>
  9. Date: Thu, 12 Nov 1992 21:20:09 GMT
  10. Lines: 44
  11.  
  12. In article <1992Nov12.211023.8188@cc.umontreal.ca> gaumondp@ERE.UMontreal.CA (Gaumond Pierre) writes:
  13. >In article <1992Nov12.041243.5542@desire.wright.edu> nseth@desire.wright.edu writes:
  14. >>I need help with generating random numbers. If I use the normail C routines
  15. >>on UNIX for generating random numbers (random, rand, etc.) everytime the
  16. >>program is executed, the sequence of random numers remains the same. 
  17. >>
  18. >>How can I fix this so that each time I execute that program, the initial (and
  19. >>thus the following sequence of) random numbers is different? On Turbo C the
  20. >>subroutine randomize() takes care of this. Is there such a routine available on
  21. >>UNIX/ULTRIX?
  22. >>
  23. >>Any help will be greatly appreciated. Thanks a lot.
  24. >
  25. >    Usually rand function has an initializer function (srand
  26. >    on my system).
  27. >
  28. >    use time(2) as the seed for srand (strip most significant
  29. >    bits).
  30. >
  31. >    For example:
  32. >        time(&seed);
  33. >        seed = seed % 100000;
  34. >        srand(seed);
  35. >
  36. >    If you have a time function giving millisecond or mocro seconds. It
  37. >    will be better. Usually, my code is suppicient.
  38. >
  39. >>Nitin Seth
  40. >>nseth@cs.wright.edu
  41. >>
  42. >
  43. >
  44. >-- 
  45. >Pierre Gaumond.        gaumondp@ERE.UMontreal.CA
  46. >Services Informatiques, Universite de Montreal. 
  47. >C.P. 6128, Succursale "A", Montreal,            
  48. >Quebec, Canada.   H3C 3J7                       
  49.  
  50.  
  51. -- 
  52. Pierre Gaumond.        gaumondp@ERE.UMontreal.CA
  53. Services Informatiques, Universite de Montreal. 
  54. C.P. 6128, Succursale "A", Montreal,            
  55. Quebec, Canada.   H3C 3J7                       
  56.