Hope that helps Looking at the graph, it seems like the area between the tick mark for 2 and 3 is the number of rolls that sum to 2. 3-4 is 3, and so on. Is it possible that between tick marks 11 and 12 contains the number of rolls that sum to 11 and 12? It could explain why the graph seems shorter on the right side than it should be, as well as why the last bar is taller than expected.
wish of those help you should keep the probability at 1/x as this will keep it as a fair dice but make the return larger then x eg x +1 so the expectance is x+1/x for example which means that they will gain money
Understanding the probability of a double-six if i roll two dice
it should still fix some issue Here's some code that handles dropping low and high rolls. Sorry for switching to Python, but I needed easy bignums and a memoization library to keep my sanity. I think the complexity is something like O(count^3 sides^2 drop_highest). The way this code works is to divide the space of possibilities for rolling count dice each with sides sides by how many dice are showing the maximum number (count_showing_max). There are binomial(count, count_showing_max) ways to achieve such a roll on uniquely labeled dice, hence the multiplier. Given count_showing_max, we can figure out how many maxed dice get dropped for being high and how many get dropped for being low (it happens) and add this sum to the outcomes for the remaining dice.
def binomial(n, k):
return math.factorial(n) // (math.factorial(k) * math.factorial(n - k))
def outcomes(count, sides, drop_highest, drop_lowest):
d = collections.Counter()
if count == 0:
d = 1
elif sides == 0:
for count_showing_max in range(count + 1): # 0..count
d1 = outcomes(count - count_showing_max, sides - 1,
max(drop_highest - count_showing_max, 0),
count_showing_max_not_dropped = max(
min(count_showing_max - drop_highest,
count - drop_highest - drop_lowest), 0)
sum_showing_max = count_showing_max_not_dropped * sides
multiplier = binomial(count, count_showing_max)
for k, v in d1.items():
d[sum_showing_max + k] += multiplier * v
d = outcomes(*args)
denominator = sum(d.values()) / 100
for k, v in sorted(d.items()):
print(k, v / denominator)
if __name__ == '__main__':
main(5, 6, 2, 2)
C++: Why does my dice roll function return only even integers when an even number of dice are rolled?
fixed the issue. Will look into that further As @Eljay points out, you are calling srand() once per roll. Since time(NULL) has a resolution of 1 second, and most likely the function is running within the same second, you are getting the same output, which means individual_roll ends up being the same number.