home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / sci / math / symbolic / 3330 < prev    next >
Encoding:
Internet Message Format  |  1992-12-24  |  1.2 KB

  1. Path: sparky!uunet!cs.utexas.edu!usc!news.service.uci.edu!beckman.com!dn66!a_rubin
  2. Newsgroups: sci.math.symbolic
  3. Subject: Re: how to randomize the elements in a list?
  4. Message-ID: <a_rubin.725214429@dn66>
  5. From: a_rubin@dsg4.dse.beckman.com (Arthur Rubin)
  6. Date: 24 Dec 92 16:27:09 GMT
  7. References: <BzrsII.7vu@news.cso.uiuc.edu>
  8. Organization: Beckman Instruments, Inc.
  9. Nntp-Posting-Host: dn66.dse.beckman.com
  10. Lines: 23
  11.  
  12. In <BzrsII.7vu@news.cso.uiuc.edu> Richard J. Gaylord <gaylord@ux1.cso.uiuc.edu> writes:
  13.  
  14. >i want to randomize the elements in a list. 
  15.  
  16. >i use  'a sample without replacement' function:
  17.  
  18. >a program that randomly selects r numbers from the list Range[n],
  19. >removing each number from the list as it is selected.
  20.  
  21. >cardDealing[n_, r_] := 
  22. >  NestList[Delete[#,
  23. >        Random[Integer,{1,Length[#]}]]&,Range[n],r]
  24.  
  25. cardDeal[n_, r_] := 
  26.   First /@ Rest[NestList[RotateLeft[Rest[#1], 
  27.        Random[Integer, {1, Length[#1] - 1}]] & , Range[0, n], r]]
  28.  
  29.  
  30. --
  31. Arthur L. Rubin: a_rubin@dsg4.dse.beckman.com (work) Beckman Instruments/Brea
  32. 216-5888@mcimail.com 70707.453@compuserve.com arthur@pnet01.cts.com (personal)
  33. My opinions are my own, and do not represent those of my employer.
  34. My interaction with our news system is unstable; please mail anything important.
  35.