       Re: Rearrangement of a sequence into random order

• To: mathgroup at smc.vnet.net
• Subject: [mg28456] Re: Rearrangement of a sequence into random order
• From: Ignacio Rodriguez <ignacio at sgirmn.pluri.ucm.es>
• Date: Thu, 19 Apr 2001 03:26:49 -0400 (EDT)
• Organization: UCM
• References: <9bjg9m\$gsn@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Try the following:

randomizer[x_,y_]:=randomizer[x,y,Part[x,Random[Integer,{1,Length[x]}]]] /;
Length[x]>0
randomizer[{x___,y_,z___},{a___},y_]:=randomizer[{x,z},{a,y}]
generator[n_]:=Part[randomizer[Table[i,{i,1,n}],{}],2]

The randomizer function works by taking a random element from the first list and
adding it to the right of the second list, in two steps, until the first list is
empty. For example,

randomizer[{1,2,3},{}]->randomizer[{1,2,3},{},2]->randomizer[{1,3},{2}]

Loren Dill wrote:

> Hi,
>
> I'm a math teacher, and need to prepare exams from time to time.  I
> typically prepare questions for the exam in a sequential order starting at
> the beginning of the material and going to the end.  I may have something
> like 20 short-answer questions.  I want a program that will randomize the
> order of the questions.  In other words, I want to provide n, the number of
> questions, and have the program provide a list of length n that contains all
> the numbers from 1 to n in a random order without any number being repeated
> or omitted.  I'm sure that this is an easy task for Mathematica, but I can't
> figure out the best way to do it.
>
> Loren Dill

--

Ignacio Rodriguez Ramirez de Arellano
Paseo Juan XXIII, 1