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: [mg43323] Re: Pick random element from list
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Sun, 24 Aug 2003 04:55:35 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 8/23/03 at 8:09 AM, a7tv-pbcm at spamex.com (Khufu) wrote:

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

Not as far as I know.

> 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?

How about

PickRandom[x_List]:=x[[Random[Integer,{1,Length@x}]]]


  • Prev by Date: Re: a bug in mathematica 5?
  • Next by Date: Re: Pick random element from list
  • Previous by thread: Re: Pick random element from list
  • Next by thread: Re: Pick random element from list