home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / pascal / 7517 < prev    next >
Encoding:
Internet Message Format  |  1992-12-16  |  1.8 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!ogicse!mimbres.cs.unm.edu!constellation!osuunx.ucc.okstate.edu!vms.ocom.okstate.edu!adams
  2. From: adams@vms.ocom.okstate.edu
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: help with die rolls...
  5. Message-ID: <1992Dec16.100336.1@vms.ocom.okstate.edu>
  6. Date: 16 Dec 92 16:03:36 GMT
  7. Article-I.D.: vms.1992Dec16.100336.1
  8. References: <1992Dec16.170959.3637@csdvax.csd.unsw.edu.au>
  9. Sender: news@osuunx.ucc.okstate.edu (USENET News System)
  10. Organization: OSU College of Osteopathic Medicine
  11. Lines: 38
  12. Nntp-Posting-Host: vms.ocom.okstate.edu
  13.  
  14. In article <1992Dec16.170959.3637@csdvax.csd.unsw.edu.au>, p2112899@csdvax.csd.unsw.edu.au writes:
  15. > Could someone please show me how to get random die rolls going.
  16. > I am writing an attribute program for a roll playing game and need to roll die
  17. > for it.
  18. > The code I have done is:
  19. > for i := 0 to 3 do  pe := pe + random(6);
  20. >
  21. > to roll a 6 sided die 3 times, but it doesn't work as it should. Some values
  22. > produced are actually lower than possible.
  23. > The minimum roll from 3 six sided die is 3, sometimes I get 2???
  24. > Any help will be appreciated.
  25. > Richard.
  26. > P2112899@csdvax.csd.unsw.edu.au
  27.  
  28.  
  29. All the RANDOM functions which accept arguments return values from ZERO to N-1,
  30. inclusive, where N is the argument supplied (in this case, 6).  If you want a
  31. number from 1 to 6, then use the following:
  32.  
  33. for i := 0 to 3 do  pe := pe + ( random(6) + 1 );
  34.  
  35. (parenthesis added for emphasis, not necessary.)
  36.  
  37. If the random function you are using does return the value of 6, then use this
  38. instead:
  39.  
  40. for i := 0 to 3 do  pe := pe + ( random(5) + 1 );
  41.  
  42.  
  43. I have had this same problem myself a few times before I figured it out :)
  44.  
  45. Steven Adams (INTERNET:  adams@vms.ocom.okstate.edu)
  46.