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: [mg43307] Re: Pick random element from list
  • From: bobhanlon at aol.com (Bob Hanlon)
  • Date: Sun, 24 Aug 2003 04:55:04 -0400 (EDT)
  • References: <bi7ngn$p7t$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

pickRandom[list_List] := list[[Random[Integer, {1,Length[list]}]]];

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

pickRandom[list]

b


Bob Hanlon

In article <bi7ngn$p7t$1 at smc.vnet.net>, "Khufu" <a7tv-pbcm at spamex.com> wrote:

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


  • Prev by Date: Re: Pick random element from list
  • Next by Date: Re: Are points co-planar in (numDimensions-1)?
  • Previous by thread: Re: Pick random element from list
  • Next by thread: RE: Pick random element from list