MathGroup Archive 1998

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

Search the Archive

RE: choose with replacement


  • To: mathgroup@smc.vnet.net
  • Subject: [mg10829] RE: [mg10800] choose with replacement
  • From: Jean-Marie THOMAS <jmthomas@cybercable.tm.fr>
  • Date: Tue, 10 Feb 1998 21:01:42 -0500
  • Return-Receipt-To: Jean-Marie THOMAS <jmthomas@cybercable.tm.fr>

Try this first: some of these functions might be a direct answer to your
problem:

<<DiscreteMath`Combinatorica`

?RandomPermutation
"RandomPermutation[n] gives a random permutation of n elements."
?RandomPermutation1
"RandomPermutation1[n] sorts random numbers to generate a random \
permutation."
?RandomPermutation2
"RandomPermutation2[n] uses random transpositions to generate random \
permutations."

If they do not, use the following code - which is far from being
optimized!

randomListTransposer[myList_List]:=Module[{ill,il,r,ol={}},
il=Length@myList;
ill=myList;
While[il>0,
r=Random[Integer,{1,il}];
AppendTo[ol,Part[ill,r]];
ill=Delete[ill,r];
il-=1];
Return[ol]]

Hope this helps,
-----------------------------------------------

Jean-Marie THOMAS
Conseil et Audit en Ingenierie de Calcul jmthomas@cybercable.tm.fr
+33 (0)3 88 32 93 64
www.cybercable.tm.fr/~jmthomas
=======================

-----Message d'origine-----
De:	Daniel Sanders [SMTP:dman777@earthlink.net] Date:	jeudi 5 fevrier
1998 06:59
A:	mathgroup@smc.vnet.net
Objet:	[mg10800] choose with replacement

Hi,

I'm new to Mathematica programming, and I'm a bit stumped to find the
code for the following maybe someone has a suggestion.

Simply put, I want to make a new list from an existing finite list by
randomly choosing an element from list_1 to be included in list_2. 
List_1 would loose that element, and the random number generator would
be reduced to correspond to the new length of the old list_1.  This
process would continue untill list_1 has no elements, and list_2 has
all the elements of list_1 reordered.

I have a feeling that this is not hard to do, but I can't seem to get it
right.  Any suggestions?

Dan





  • Prev by Date: Re: Truth-Plot
  • Next by Date: Mathematica 3.0.2, NeXT Intel
  • Prev by thread: RE: choose with replacement
  • Next by thread: Re: choose with replacement