Random sequence generator with some specifications
February 9, 2014 12:53 PM   Subscribe

Let's say I have things 1, 2, 3 and 4. I want a sequence of 20 numbers which are either 1, 2, 3 or 4. I want to use all of these numbers an equal number of times, and once that number has exhausted its chances I want it to stop being used in the sequence. Is there a free program, or an easy way to do this in Excel / Google Spreadsheet?
posted by codacorolla to Computers & Internet (6 answers total) 2 users marked this as a favorite
Could you shuffle a list of five 1s, five 2s, five 3s, and five 4s instead? I think that'd get you the same results.
posted by Nonsteroidal Anti-Inflammatory Drug at 1:00 PM on February 9 [5 favorites]

You can do this in R:

nums = rep(1:4, 5)

Repeat as necessary.
posted by one_bean at 1:07 PM on February 9

There are at least a couple of ways to do this using random.org, a neat web site that lets you generate list of random numbers:

1) Use their "list randomizer". Enter this list (with one number on each line): "1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4". Then randomize! (Use advanced mode to get results as a "bare bones text document")

2) Use their card shuffler. Create a deck with five sets of cards from 1 (ace) to 5. Shufffle! Here are results.
posted by ManInSuit at 1:13 PM on February 9 [1 favorite]

Thanks! I figured there was an easy way to this, but didn't know the term was list shuffling. Any one of these methods should work.
posted by codacorolla at 1:30 PM on February 9

The term comes from "shuffling a deck of cards". Same usage.
posted by Chocolate Pickle at 1:49 PM on February 9

One more in Python to round things out:

from random import shuffle
seq = [1]*5 + [2]*5 + [3]*5 + [4]*5

posted by The Michael The at 2:03 PM on February 9 [2 favorites]

« Older Here's an assertion one hears ...   |  I've been asked by a friend of... Newer »

You are not logged in, either login or create an account to post comments