dice

XKCD - Random Number

Could someone explain if and why the following random number function from XKCD works? I have never quite been able to understand it. I ask the question on SO hoping to find a more "human" explanation that could be understood by me. ...

Determine Frequency of numbers showing up in dice rolls

For a game I'm trying to determine the frequency that a certain # will show up at a given # of dice being rolled. I know... that question seems odd. Let me try to explain it with real numbers. So, for 1 die, the frequency for each number will be identical. 1-6 will show up equal number of times. Now for 2 dice, things get different. I ...

Evaluate dice rolling notation strings

Rules Write a function that accepts string as a parameter, returning evaluated value of expression in dice notation, including addition and multiplication. To clear the things up, here comes EBNF definition of legal expressions: roll ::= [positive number], "d", positive number entity ::= roll | positive number expression ::= entity {...

Problem with random dice rolling in C# console application

I am writing dice roller program in C# console. I am giving two input Enter the size of the dice and Enter how times you want to play. Suppose dice size is 6 and 10 times i have played. Output is coming: 1 was rolled 2 times 2 was rolled 7 times 3 was rolled 8 times 4 was rolled 7 times 5 was rolled 4 times 6 was rolled 5 ...

Combinitorics Counting Puzzle: Roll 20, 8-sided dice, what is the probability of getting at least 5 dice of the same value

Assume a game in which one rolls 20, 8-sided die, for a total number of 8^20 possible outcomes. To calculate the probability of a particular event occurring, we divide the number of ways that event can occur by 8^20. One can calculate the number of ways to get exactly 5 dice of the value 3. (20 choose 5) gives us the number of orders o...

Parsing dice expressions (e.g. 3d6+5) in C#: where to start?

So I want to be able to parse, and evaluate, "dice expressions" in C#. A dice expression is defined like so: <expr> := <expr> + <expr> | <expr> - <expr> | [<number>]d(<number>|%) | <number> <number> := positive integer So e.g. d6+20-2d3 would be allowed, and should evaluate as rand.Next(1, 7) + 2...

C# code only gives expected results on step through?

Ok so I have a dice throw app... When I step through the code it functions normally and 'results' contains the correct number of throw results and they appear to be random, when I leave the code to run and do exactly the same thing it produces a set of identical numbers. I'm sure this is a logical error I cannot see but fiddling with i...

PHP choose the side a die has?

The php section of my code is not doing the correct operations when the user submits his/her number, for example, if the user submits 5, I want the rand function to randomly output 5 as the number selected; however, my code sometimes works and at other times does not work. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "...

Trying to generate several digit intervals in one number (LUA)

Basically I have to use a random function that can return a number between 0 and 2^16-1. I am trying to make use of this and generate let's say, 6 intervals between 1 and 6 (thinking of dice poker). Basically use that one number that is randomly generated for me (I can specify range only) and preferably only have to call it once. Then t...

Does msvcrt.dll use a linear congruential generator for its rand() function?

I am trying to predict the output of a program that uses msvcrt's rand() function for generating the face of three dice. I believe the code is something like: dice[0] = rand() % 6 + 1; dice[1] = rand() % 6 + 1; dice[2] = rand() % 6 + 1;, and I was wondering if I could use a prediction program for linear congruential generators to predict...

looping in unit test bad?

I have a unit test that relies on a random dice roll. I roll a 20 sided die and if the value is 20 it counts as a critical hit. What I'm doing right now is rolling the 20 sided die up to 300 times. If any one of those rolls is a 20 then I know I had a critical hit. Here's what the code looks like: public class DiceRoll { public in...

Dice odds: Simulating a game of Craps

My brother turns 21 in a couple of weeks and my parents and I are taking him to Las Vegas. For my 21st, I brought $200 to gamble in Vegas and came home with around $450, mostly from playing craps. I plan on bringing $200 again for this trip and before I go I thought I'd run some craps simulations to see if I can double my money again. I...

Calculating odds distribution with 6-sided dice

I'm trying to calculate the odds distribution of a changing number of 6-sided die rolls. For example, 3d6 ranges from 3 to 18 as follows: 3:1, 4:3, 5:6, 6:10, 7:15, 8:21, 9:25, 10:27, 11:27, 12:25, 13:21, 14:15, 15:10, 16:6, 17:3, 18:1 I wrote this php program to calculate it: function distributionCalc($numberDice,$sides=6) { for ( $...

Generate a matrix of all possible outcomes for throwing n dice (ignoring order)

In cases where order does matter, it's rather easy to generate the matrix of all possible outcomes. One way for doing this is using expand.grid as shown here. What if it doesn't? If I'm right, the number of possible combinations is (S+N-1)!/S!(N-1)!, where S is the number of dice, each with N sides numbered 1 through N. (It is differ...

recursion resulting in extra unwanted data

I'm writing a module to handle dice rolling. Given x die of y sides, I'm trying to come up with a list of all potential roll combinations. This code assumes 3 die, each with 3 sides labeled 1, 2, and 3. (I realize I'm using "magic numbers" but this is just an attempt to simplify and get the base code working.) int[] set = { 1...

Determine if a dice roll contains certain combinations?

I am writing a dice game simulator in Python. I represent a roll by using a list containing integers from 1-6. So I might have a roll like this: [1,2,1,4,5,1] I need to determine if a roll contains scoring combinations, such as 3 of a kind, 4 of a kind, 2 sets of 3, and straights. Is there a simple Pythonic way of doing this? I've...

Java setter, getter (rolling a die)

I have some questions about java. There are two questions in the code (I left them as comments). Also what is the purpose of using setting and getting methods? Could you please explain it very briefly. I am a beginner. Thank you :) public class Die { private final int MAX = 6; private int faceValue; public Die() { ...