need a dice simulation software

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

need a dice simulation software

I'm involved in a project and need to create a dice simulation program using the following custom dice:
dice 1: -5, 0, 0, +5, +5, +5
dice 2: -15, -10, 0, +10, +10, +15
dice 3: -20, -15, -10, +10, +20, +25

and I'd need to output this to a .csv file or .xls so I can graph/evaluate it.

Using Excel (and a healthy dose of Bing), I was able to come up with the following:

dice 1: =INDEX({-5,0,0,5,5,5},RANDBETWEEN(1,6))
dice 2: =INDEX({-15,-10,0,10,10,15},RANDBETWEEN(1,6))
dice 3: =INDEX({-20,-15,-10,10,20,25},RANDBETWEEN(1,6))

Now, is there any way in Excel to automate this and graph it? I'm thinking maybe some sort of macro? (which I don't know how to do).

If not, can anybody point me on a tutorial (I'm still looking as I write this) on how to do this?

Thanks.
Venii, vidii, vicii
Wii came, Wii saw , Wii conquered
Sargent Duck
Grand Gerbil Poohbah
Silver subscriber

Posts: 3086
Joined: Thu Mar 13, 2003 8:05 pm
Location: In my secret cave that has bats

Re: need a dice simulation software

What are you going to graph? Timelines? Sampling error?

If you're going to be doing a lot of this stuff in the future, it might be worth learning a stat software language. All this stuff, including graphing, would be less than 40 lines of code in R.
wibeasley
Gerbil Elite

Posts: 952
Joined: Sat Mar 29, 2008 3:19 pm
Location: Norman OK

Re: need a dice simulation software

Code: Select all
`rm(list=ls(all=TRUE)) #Remove any existing variable values.replicationCount <- 10000000faceIDs <- 1:6diceCount <- 3dice1Values <- c(-5, 0, 0, 5, 5, 5)dice2Values <- c(-15, -10, 0, 10, 10, 15)dice3Values <- c(-20, -15, -10, 10, 20, 25)diceValues <- cbind(dice1Values, dice2Values, dice3Values) #Bind them as columns.sampledFaces <- matrix(sample(x=faceIDs, size=diceCount*replicationCount, replace=T), ncol=diceCount) #Store the index of the sampled face; this is where most of the work is done.sampledValues <- matrix(rep(NA, length(sampledFaces)), ncol=diceCount) #For storing the value of the rolled dice.for( diceIndex in 1:diceCount ) {  sampledValues[, diceIndex] <- diceValues[sampledFaces[, diceIndex], diceIndex]}expectedValues <- colMeans(diceValues)sampleValues <- colMeans(sampledValues)rbind(expectedValues, sampleValues) #Bind them as rows.`

The output is
Code: Select all
`               dice1Values dice2Values dice3ValuesexpectedValues    1.666667    1.666667    1.666667sampleValues      1.666109    1.666702    1.674519`

I bet you could make two rough graphs in 15-20 lines of code.
Edit: To simulate loaded dice, specify a vector as the 'prob' argument in the 'sample' function.
wibeasley
Gerbil Elite

Posts: 952
Joined: Sat Mar 29, 2008 3:19 pm
Location: Norman OK

Re: need a dice simulation software

FYI, the singular is "die." "Dice" is a plural noun. For a small number of fair dice with a small number of sides as in your example, you could enumerate them all in a spreadsheet easily enough. You have only 216 possible combinations with three six-sided dice.
JustAnEngineer
Gerbil God
Gold subscriber

Posts: 16356
Joined: Sat Jan 26, 2002 7:00 pm
Location: The Heart of Dixie

Re: need a dice simulation software

How automated does it need to be? You can easily copy the formula into multiple cells by selecting a vertical range and using the "fill down" shortcut (Ctrl-D). Force a recalculate (Ctrl-Alt-F9 in Excel, Ctrl-Shift-F9 in OpenOffice Calc) and you should get a new set of random numbers.

Caveat: If you need results which will pass rigorous statistical tests for randomness, I am not sure how much I would trust the spreadsheet's built-in random number generator.

On the whole die/dice thing: Gotta love the English language! (For consistency's sake, the singular of "mice" should really be "mie". Or maybe the singular of "dice" should be "douse"! )

Edit: This thread wasn't inspired by last Friday's xkcd by any chance, was it?
The years just pass like trains. I wave, but they don't slow down.
-- Steven Wilson
just brew it!
Gold subscriber

Posts: 40837
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: need a dice simulation software

What do you actually want to get out of it?

Mean, variance, probability distribution graph, cumulative distribution graph? The first two are calculable without resorting to a random number generator, and the graphs are easy enough to plot by generating all 216 values in excel with a tiny amount of copy and paste action, then probably something with the histogram function?

Or are you wanting to simulate actual throws of the 3 dice, and have a list of result 1, result 2, ...?
mboza

Posts: 203
Joined: Fri Sep 15, 2006 6:52 am

Re: need a dice simulation software

Apologies for the lateness of the reply. Work was a gong show (sigh, my computer crashed) and right after I went out, so I'm just now sitting down on the computer.

Let me try to answer your questions, starting with a clarification for mboza (and everybody else). I kinda knew what I wanted yesterday, but couldn't put it into words. Today I can.

First, what I want to insure is that the dice have a really high confidence interval with the rolls (apologies if I muck this next part up. I hated stats and fell asleep during class oh so many years ago). My project for the die is to be as random as possible, such that there is no discernable pattern.

In my project, participants can play either die 1, 2, 3, dice 1&2, 2&3 or all three. What I want to make sure is that there is no discernable pattern to how the dice are rolled.

For example, let's say (hypothetically speaking and making these numbers up) that for the first 10 throws of the die, die 2 has a tendency to roll positives, then plummet with negatives. This behaviour (rolling positives right off the bat) would be very bad as particpants would be able to start seeing a pattern, that they should roll die 2 for the first couple of rolls, then switch to another die before the negatives start coming. I want to insure that when die 2 (or any dice is rolled), that there is no discernable pattern to how it rolls.

Does that make sense? I can provide a specific example of exactly what I'm doing, but I think this should suffice. If not, let me know and I'll attempt to re-explain.

JustAnEngineer wrote:FYI, the singular is "die." "Dice" is a plural noun.
moose/meese? Your FYI has been noted, and I hope I've corrected the usage going forward.

just brew it! wrote:How automated does it need to be? You can easily copy the formula into multiple cells by selecting a vertical range and using the "fill down" shortcut (Ctrl-D). Force a recalculate (Ctrl-Alt-F9 in Excel, Ctrl-Shift-F9 in OpenOffice Calc) and you should get a new set of random numbers.
I have no problem hitting "refresh" in Excel. Ideally I'd like a good sample size of 1000 rolls or so. So automated = bonus.

just brew it! wrote:Caveat: If you need results which will pass rigorous statistical tests for randomness, I am not sure how much I would trust the spreadsheet's built-in random number generator.
Haha, agreed. I have Excel and know how to work in it. I don't know how to program in any language (well, that's not true. I did teach myself CSS)

just brew it! wrote:Edit: This thread wasn't inspired by last Friday's xkcd by any chance, was it?
LOL. Nope.
Venii, vidii, vicii
Wii came, Wii saw , Wii conquered
Sargent Duck
Grand Gerbil Poohbah
Silver subscriber

Posts: 3086
Joined: Thu Mar 13, 2003 8:05 pm
Location: In my secret cave that has bats

Re: need a dice simulation software

The Excel RNG itself should be random enough for a human not to detect a bias. But it's still a good idea to test the long-run averages, to identify any implmentation/coding mistakes that you've made.

If you're worried about them seeing a pattern, consider using a predetermined sequence. One that's constant across all subjects. It's not that unlikely to roll five out of six heads of a coin (=9.3% = 6*.5^6; and another 9% for 5/6 tails), but many people will assign a pattern to it. If you have a large sample size, many of them will receive one of those apparently nonrandom sequences. A predetermined, constant sequence also will minimize an unnecessary source of between-subject variability, which will improve the power of your statistical test.

What's being graphed?
wibeasley
Gerbil Elite

Posts: 952
Joined: Sat Mar 29, 2008 3:19 pm
Location: Norman OK

Re: need a dice simulation software

FWIW Debian's got a rolldice package which can roll arbitrary types and numbers of dice. You can grab the source code and I'd bet it would compile in Cygwin.

http://packages.debian.org/squeeze/rolldice
Hakkaa päälle!
i5-2500K@4.3|Asus P8P67-LE|8GB DDR3-1600|Powercolor R7850 2G|1.5TB 7200.11|1988 Model M|Saitek X-45|Logitech MX 518 & F310|Dell 2209WA|Sennheiser PC151|Asus Xonar DX
bthylafh
Grand Gerbil Poohbah

Posts: 3472
Joined: Mon Dec 29, 2003 11:55 pm
Location: Southwest Missouri, USA

Re: need a dice simulation software

Hey guys, thanks for all your help.

My problem was that I knew what I wanted, but I didn't really. Eventually, haha, I was able to get what I wanted using a histograph.

Just wanted to say thanks for your help.
Venii, vidii, vicii
Wii came, Wii saw , Wii conquered
Sargent Duck
Grand Gerbil Poohbah
Silver subscriber

Posts: 3086
Joined: Thu Mar 13, 2003 8:05 pm
Location: In my secret cave that has bats