Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: Needing a Random List of Non-repeating Values whose

  • To: mathgroup at smc.vnet.net
  • Subject: [mg129514] Re: Needing a Random List of Non-repeating Values whose
  • From: James Stein <mathgroup at stein.org>
  • Date: Sat, 19 Jan 2013 01:16:09 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <20130118055413.82B97691E@smc.vnet.net>

I looks like the tile of your post was truncated, so I'm not quite
sure what you're asking.

Here is a shuffle algorithm:

shuffle[s_List] := Module[{a = s, f, i, j, n = s // Length},
   f[i_] := (j = RandomInteger[{1, n}];
     {a[[i]], a[[j]]} = {a[[j]], a[[i]]});
   Map[f, Range[n]];
   a
   ];

Perhaps what you want is:
   ril [ range_Integer] := Shuffle [ Range [ range ] ]
Or if you wish an incomplete set of k items, without duplicates:
   ril [ range_Integer, k_Integer ] := Take [Shuffle [ Range [ range ] ] , k ]

HTH


On Thu, Jan 17, 2013 at 9:54 PM,  <brtubb090530 at cox.net> wrote:
> Consider the following:
>
> ril[range_Integer]:= RandomInteger[{1,range},range]
>
> This function is almost what I want; but I need one which doesn't include any repeated values. This is intended for use, for example, for a card deck, or dice, etc.
>



  • Prev by Date: Re: Needing a Random List of Non-repeating Values whose Range and Length
  • Next by Date: Re: TraditionalForm Plot
  • Previous by thread: Re: Needing a Random List of Non-repeating Values whose
  • Next by thread: Re: Needing a Random List of Non-repeating Values whose