MathGroup Archive 2003

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

Search the Archive

RE: Pick random element from list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43297] RE: [mg43276] Pick random element from list
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sun, 24 Aug 2003 04:54:55 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

K,

pickRandom[list_?VectorQ] := Part[list, Random[Integer, {1, Length[list]}]]

list = {1, 2, 3, a, b, c};

Table[pickRandom[list], {25}]
{1, 2, 2, 2, b, b, a, 2, b, c, 2, b, 3, b, c, a, c, 3, c, c, 3, b, 1, 1, 2}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/ 

From: Khufu [mailto:a7tv-pbcm at spamex.com]
To: mathgroup at smc.vnet.net

Hi Mathgroup,

Is there a built-in function to pick a random element from a list?

I'm looking for something simple, like:

list = {1,2,3,a,b,c}
PickRandom[list] returns "b", etc.

If this isn't built-in, can anyone suggest a simple/efficient
implementation?

Many thanks,
-K


  • Prev by Date: Re: Those Pesky Minus Signs
  • Next by Date: Re: Data Manipulation
  • Previous by thread: Re: Pick random element from list
  • Next by thread: Help! on vector field around equilibrium of nonlinear system