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