MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Random Order of a Set of Numbers



At 21:01 10.02.98 -0500, JD Faith wrote:
>HELP PLEASE...
>
>I'm a math moron looking for a formula to compute the following problem:
>I need to generate a random list of the numbers 1-36, 33 times.  The
>idea being to replicate the drawing 0f the numbers 1-36 from a hat 33
>times.
>
>Any assistance is appreciated.  Give your buddies a laugh by posting
>responses to the Newsgroup or save me some pride by e-mailing me
>directly.
>
>Thank you...
>

several mails recently touched on the topic of selecting random elements
or reordering lists in a certain way.

For all cases where numbers are drawn from a hat **without putting the
selected numbers back in the hat, giving them a chance to come up
again**, this operation amounts to a permutation of these objects. Now,
permutations are best handled as ... permutations (on the integers).
The add-on DiscreteMath`Permutations` lets you get at random
permutations, with the somewhat surprising name RandomPermutation[ size
]   (;-))

say that you have a list of 5 objects  obj={first, sec, third,
fourth,fifth} and you want to permute them, simply do
jostle=RandomPermutation[ 5 ]; obj[[ jostle ]]

if you define "jostle" with ":=" instead of " =" then you obtain a fresh
randomjostle each time it is called\executed.

Personally, I would have liked to see the function "Ordering[ list ]" as
part of the 
DiscreteMath`Permutations` packages, instead of the heavy 
..`Combinatorica` package where it now resides. 
It can however be made "by hand" with a one-liner :

Ordering[ obj_List]:=Last /@ Sort[Transpose[{ obj , Range[Length[obj]]
}] ]

this nice function gives the permutation that puts  obj into order :

  obj [[ Ordering @ obj  ]] is equivalent to Sort [ obj ]

The advantage is that such permutations can be written in cycle form,
which makes them easier to "understand" :
ToCycles[ ] and FromCycles[ ] will do just that.

<<DiscreteMath`Permutations`
Table[ RandomPermutation[36] , {33} ] will give J.D. Faith the table he
wants.


wouter.

NV Vandemoortele Coordination Center Oils & Fats Applied Research
Prins Albertlaan 79
Postbus 40
B-8870 Izegem (Belgium)
Tel: +/32/51/33 21 11
Fax: +/32/51/33 21 75
vdmcc@vandemoortele.be




  • Prev by Date: Re: Error Bars
  • Next by Date: RE: Holding name of argument
  • Prev by thread: Random Order of a Set of Numbers
  • Next by thread: Re: Random Order of a Set of Numbers