The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Needing a Random List of Non-repeating Values whose
Replies: 4   Last Post: Jan 20, 2013 1:25 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
James Stein

Posts: 130
Registered: 5/8/10
Re: Needing a Random List of Non-repeating Values whose
Posted: Jan 19, 2013 1:14 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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]];

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 ]


On Thu, Jan 17, 2013 at 9:54 PM, <> 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.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.