Is this an equal chance on a dice roll?

0 favourites
  • 3 posts
From the Asset Store
Fully animated four sided dice, top down wooden tray and dice throwing cup
  • Hi there, everyone.

    I am programming a dice roll into a function that does exploding dice on 10s and critical failures on 1s.

    I am currently "using int(random(1,11))", since random picks a value one less than the second number, this should roll between 1 and 10.

    However, I suspect that these numbers are skewed against 1s and 10s because of int. Int rounds to the nearest integer, so when I roll my random value, a 2 would trigger on a value between 1.5 and 2.49, right? That also means that a 1 can only trigger from 1 to 1.49 and a 10 only on 9.5 to 10, reducing the probability of those numbers by half.

    Doesn't that mean that I should use "int(random(0.5,11.5))" in order to let 1s roll on 0.5 to 1.49 and tens to roll on 9.5 and 10.49?

    Tagged:

  • I like to use 'floor' to round down and it should work well here, 10.99 = 10 and 1.99 = 1 etc.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • int works the same as floor. They both round down, so your probability will be equal for all dice rolls with int(random(1,11)).

    Unless they changed the behavior of int to just truncate the float to an int. But you would only see that with negative numbers.

    int(0.5) = 0

    round(0.5) = 1

    floor(0.5) = 0

    ceil(0.5) = 1

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)