Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13204 > unrolled thread

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

Started byJames Stein <mathgroup@stein.org>
First post2013-01-19 06:14 +0000
Last post2013-01-19 06:14 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Needing a Random List of Non-repeating Values whose James Stein <mathgroup@stein.org> - 2013-01-19 06:14 +0000

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

FromJames Stein <mathgroup@stein.org>
Date2013-01-19 06:14 +0000
SubjectRe: Needing a Random List of Non-repeating Values whose
Message-ID<kdddjj$a20$1@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@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.
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web