Question about different die rolls.
TheTinman
Member Posts: 74
I have a script with these lines in it.
It works fine as is. Also works if changed to d100. My question being. Why does it not compile if changed to d40?
int nInt; nInt = d20(); if (nInt==1)
It works fine as is. Also works if changed to d100. My question being. Why does it not compile if changed to d40?
0
Comments
If you want to have a d40() roll you can do the following:
All the dice functions take an int parameter that specifies the number of dice to roll. With that code it will be impossible to make a roll of 1 but if you subtract 1 from the result of d20(), 40 becomes impossible to roll. That makes @Daz's code more accurate.
If you are on Windows you can check most of EE's functions in the searchable, offline version of the Lexicon.
TR
int iD40=DNum(40,1);
Returns a random integer between 1 and 40
int iD40by2=DNum(40,2);
Returns a random integer between 2 and 80
2d20 is not the same as d40. Amongst other things, it can never be 1.
TR
No. In most programming languages random function uses a float type and starts at 0. When casting to integer the float gets rounded down. So above code gives you a number from 0 to 39.
Also in general rolling multiple dice and adding them gives you a complete different probability distribution than rolling a single larger die. The more dice you throw the more likely you end up with a result in the middle of the spectrum. For example 2D6 gives you a higher chance for a 7 than the other results whereas a D12 treats all possible results equally.