Menu
News
All News
Dungeons & Dragons
Level Up: Advanced 5th Edition
Pathfinder
Starfinder
Warhammer
2d20 System
Year Zero Engine
Industry News
Reviews
Dragon Reflections
White Dwarf Reflections
Columns
Weekly Digests
Weekly News Digest
Freebies, Sales & Bundles
RPG Print News
RPG Crowdfunding News
Game Content
ENterplanetary DimENsions
Mythological Figures
Opinion
Worlds of Design
Peregrine's Nest
RPG Evolution
Other Columns
From the Freelancing Frontline
Monster ENcyclopedia
WotC/TSR Alumni Look Back
4 Hours w/RSD (Ryan Dancey)
The Road to 3E (Jonathan Tweet)
Greenwood's Realms (Ed Greenwood)
Drawmij's TSR (Jim Ward)
Community
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Resources
Wiki
Pages
Latest activity
Media
New media
New comments
Search media
Downloads
Latest reviews
Search resources
EN Publishing
Store
EN5ider
Adventures in ZEITGEIST
Awfully Cheerful Engine
What's OLD is NEW
Judge Dredd & The Worlds Of 2000AD
War of the Burning Sky
Level Up: Advanced 5E
Events & Releases
Upcoming Events
Private Events
Featured Events
Socials!
EN Publishing
Twitter
BlueSky
Facebook
Instagram
EN World
BlueSky
YouTube
Facebook
Twitter
Twitch
Podcast
Features
Top 5 RPGs Compiled Charts 2004-Present
Adventure Game Industry Market Research Summary (RPGs) V1.0
Ryan Dancey: Acquiring TSR
Q&A With Gary Gygax
D&D Rules FAQs
TSR, WotC, & Paizo: A Comparative History
D&D Pronunciation Guide
Million Dollar TTRPG Kickstarters
Tabletop RPG Podcast Hall of Fame
Eric Noah's Unofficial D&D 3rd Edition News
D&D in the Mainstream
D&D & RPG History
About Morrus
Log in
Register
What's new
Search
Search
Search titles only
By:
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Menu
Log in
Register
Install the app
Install
Community
General Tabletop Discussion
*TTRPGs General
Probability Distribution of Dice
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="nsruf" data-source="post: 764788" data-attributes="member: 872"><p>Here is a matlab function that should do the trick with a time complexity of (p^2)*(n^2) instead of the awful p^n for complete enumeration. So you can calculate the probabilities for a moderate number of dice (e.g. 10d6) in reasonable time. It uses a recursive scheme without actual recursion:</p><p></p><p><span style="font-family: 'courier new'"></span></p><p><span style="font-family: 'courier new'">function d = roll(n, p)</span></p><p><span style="font-family: 'courier new'">% determine probabilities to roll less than</span></p><p><span style="font-family: 'courier new'">% or equal to any number with n p-sided dice</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> N = n * p;</span></p><p><span style="font-family: 'courier new'"> % maximal roll result</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> last = [ones(1, p), zeros(1, N - p)];</span></p><p><span style="font-family: 'courier new'"> % contains the number of combinations</span></p><p><span style="font-family: 'courier new'"> % for rolling a given number found in the</span></p><p><span style="font-family: 'courier new'"> % previous iteration of the outer for-loop;</span></p><p><span style="font-family: 'courier new'"> % initialized with the single die roll</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> next = zeros(1, N);</span></p><p><span style="font-family: 'courier new'"> % contains the number of combinations</span></p><p><span style="font-family: 'courier new'"> % for rolling a given number if you add</span></p><p><span style="font-family: 'courier new'"> % one more die</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> for i = 2:n;</span></p><p><span style="font-family: 'courier new'"> % number of dice considered for</span></p><p><span style="font-family: 'courier new'"> % calculating next</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> mu = ceil((p + 1) * i / 2);</span></p><p><span style="font-family: 'courier new'"> % expectation value, rounded up</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> for j = i:mu; for k = 1<img src="https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f61b.png" class="smilie smilie--emoji" loading="lazy" width="64" height="64" alt=":p" title="Stick out tongue :p" data-smilie="7"data-shortname=":p" />;</span></p><p><span style="font-family: 'courier new'"> % determine values in next up to expectation</span></p><p><span style="font-family: 'courier new'"> % mu; k is the number rolled on the additional</span></p><p><span style="font-family: 'courier new'"> % die</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> if j - k >= i - 1;</span></p><p><span style="font-family: 'courier new'"> % if it is possible to roll k on one die and</span></p><p><span style="font-family: 'courier new'"> % still get a result of j</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> next(j) = next(j) + last(j - k);</span></p><p><span style="font-family: 'courier new'"> % add the number of possibilities to roll</span></p><p><span style="font-family: 'courier new'"> % (j - k) with (i - 1) dice</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> end; end; end;</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> I = i * p;</span></p><p><span style="font-family: 'courier new'"> % maximal roll on i dice</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> for j = (mu + 1):I;</span></p><p><span style="font-family: 'courier new'"> % determine remaining values in next</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> next(j) = next(I + i - j);</span></p><p><span style="font-family: 'courier new'"> % find values larger then mu by symmetry</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> end;</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> last = next;</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> next = zeros(1, N);</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> end;</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> d = cumsum(last) / (p ^ n);</span></p><p><span style="font-family: 'courier new'"> % probability to roll less is cumulative sum</span></p><p><span style="font-family: 'courier new'"> % divided by total number of combinations</span></p><p><span style="font-family: 'courier new'"> </span></p><p><span style="font-family: 'courier new'"> d = [n:N; d(n:N)];</span></p><p><span style="font-family: 'courier new'"> % first row of output contains possible rolls,</span></p><p><span style="font-family: 'courier new'"> % second row contains probability to roll</span></p><p><span style="font-family: 'courier new'"> % equal or less</span></p></blockquote><p></p>
[QUOTE="nsruf, post: 764788, member: 872"] Here is a matlab function that should do the trick with a time complexity of (p^2)*(n^2) instead of the awful p^n for complete enumeration. So you can calculate the probabilities for a moderate number of dice (e.g. 10d6) in reasonable time. It uses a recursive scheme without actual recursion: [font=courier new] function d = roll(n, p) % determine probabilities to roll less than % or equal to any number with n p-sided dice N = n * p; % maximal roll result last = [ones(1, p), zeros(1, N - p)]; % contains the number of combinations % for rolling a given number found in the % previous iteration of the outer for-loop; % initialized with the single die roll next = zeros(1, N); % contains the number of combinations % for rolling a given number if you add % one more die for i = 2:n; % number of dice considered for % calculating next mu = ceil((p + 1) * i / 2); % expectation value, rounded up for j = i:mu; for k = 1:p; % determine values in next up to expectation % mu; k is the number rolled on the additional % die if j - k >= i - 1; % if it is possible to roll k on one die and % still get a result of j next(j) = next(j) + last(j - k); % add the number of possibilities to roll % (j - k) with (i - 1) dice end; end; end; I = i * p; % maximal roll on i dice for j = (mu + 1):I; % determine remaining values in next next(j) = next(I + i - j); % find values larger then mu by symmetry end; last = next; next = zeros(1, N); end; d = cumsum(last) / (p ^ n); % probability to roll less is cumulative sum % divided by total number of combinations d = [n:N; d(n:N)]; % first row of output contains possible rolls, % second row contains probability to roll % equal or less[/font] [/QUOTE]
Insert quotes…
Verification
Post reply
Community
General Tabletop Discussion
*TTRPGs General
Probability Distribution of Dice
Top