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="Drawmack" data-source="post: 765463" data-attributes="member: 4981"><p>First I have optimized the recursion so you only call it once for each die in your initial set. For example 100d10 would call this 100 times, for each result you queried it for.</p><p></p><p>[code][color=white]</p><p> function getPossibleCombinations($result,$arySides,$position) {</p><p> if($result < count($arySides)) {return 0;}</p><p> $current = $arySides[$position];</p><p> $min = count($arySides)-1;</p><p> $max = array_sum($arySides) - $current;</p><p> $minCurrent = $result - $max;</p><p> if($minCurrent < 1) {$minCurrent = 1;}</p><p> $maxCurrent = $result - $min;</p><p> if($maxCurrent > $current) {$maxCurrent = $current;}</p><p> $set = $maxCurrent - $minCurrent + 1;</p><p> if($position == (count($arySides)-1)) {return $set;}</p><p> else {return($set + getPossibleCombinations($result,$arySides,$position+1));}</p><p> }</p><p>[/color][/code]</p><p></p><p>Code explained:</p><p>$result = the result you a querying for the number of sets that will produce it.</p><p>$arySides = is an array that holds the number of sides on your die. (i.e. (4,6,6,8) would be 1d4, 2d6, 1d8)</p><p>$position = which die you are looking at on this iteration, always 0 when you call the function it just uses it internally so it must be there.</p><p></p><p>now that the parameters are out of the way here's how the algorithm works</p><p>test the requested result for existenc in the supplied array</p><p>get the number of sides on the die for this iteration</p><p>calculate the minimum that can be rolled excluding this die</p><p>calculate the maximum that can be rolled excluding this die</p><p>calculate the minimum that is needed from this die to roll result</p><p>make sure minimum is 1</p><p>calculate the maximum that can be rolled from this die to roll result</p><p>make sure maximum is <= die sides</p><p>calculate the size of the set that can be used from this die</p><p>either return set</p><p>or return set * call function again with the next position.</p><p></p><p>The problem with the algorithm is that is counts doubles, tripples, etc. multiple times and I don't know how to make that stop.</p><p></p><p>for example rolling 3d4 and query for 3. We all know the answer is 1, however with this algorithm it reports 3 because each 1 can be in any position.</p></blockquote><p></p>
[QUOTE="Drawmack, post: 765463, member: 4981"] First I have optimized the recursion so you only call it once for each die in your initial set. For example 100d10 would call this 100 times, for each result you queried it for. [code][color=white] function getPossibleCombinations($result,$arySides,$position) { if($result < count($arySides)) {return 0;} $current = $arySides[$position]; $min = count($arySides)-1; $max = array_sum($arySides) - $current; $minCurrent = $result - $max; if($minCurrent < 1) {$minCurrent = 1;} $maxCurrent = $result - $min; if($maxCurrent > $current) {$maxCurrent = $current;} $set = $maxCurrent - $minCurrent + 1; if($position == (count($arySides)-1)) {return $set;} else {return($set + getPossibleCombinations($result,$arySides,$position+1));} } [/color][/code] Code explained: $result = the result you a querying for the number of sets that will produce it. $arySides = is an array that holds the number of sides on your die. (i.e. (4,6,6,8) would be 1d4, 2d6, 1d8) $position = which die you are looking at on this iteration, always 0 when you call the function it just uses it internally so it must be there. now that the parameters are out of the way here's how the algorithm works test the requested result for existenc in the supplied array get the number of sides on the die for this iteration calculate the minimum that can be rolled excluding this die calculate the maximum that can be rolled excluding this die calculate the minimum that is needed from this die to roll result make sure minimum is 1 calculate the maximum that can be rolled from this die to roll result make sure maximum is <= die sides calculate the size of the set that can be used from this die either return set or return set * call function again with the next position. The problem with the algorithm is that is counts doubles, tripples, etc. multiple times and I don't know how to make that stop. for example rolling 3d4 and query for 3. We all know the answer is 1, however with this algorithm it reports 3 because each 1 can be in any position. [/QUOTE]
Insert quotes…
Verification
Post reply
Community
General Tabletop Discussion
*TTRPGs General
Probability Distribution of Dice
Top