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
*Pathfinder & Starfinder
Probability in Char. Gen.
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="drothgery" data-source="post: 2187697" data-attributes="member: 360"><p>My VB.NET Monte Carlo attempt is coming with around 30.9, a little higher than most of you got, though I'm playing with the VS.NET 2005 Beta 2 compilers, and this code uses some new features, so I'm wondering if I'm making any mistakes...</p><p></p><p>[sblock][code]</p><p>Private Sub GoBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoBtn.Click</p><p> Dim iterationsCount As Integer</p><p> Dim totalPoints As Long = 0</p><p> Dim avgPoints As Double</p><p></p><p> If Integer.TryParse(Me.NumTb.Text, iterationsCount) Then</p><p> Dim rnd As New System.Random</p><p></p><p> For i As Integer = 0 To iterationsCount</p><p> totalPoints += RollCharacter(rnd)</p><p> Next</p><p></p><p> avgPoints = totalPoints / iterationsCount</p><p> RsltsLbl.Text = avgPoints.ToString</p><p> End If</p><p> End Sub</p><p></p><p> Private Function RollCharacter(ByVal rnd As Random) As Integer</p><p> Dim charPoints As Integer = 0</p><p> Dim diceRslts As New List(Of Integer)</p><p> Dim rollValue As Integer</p><p> Dim maxVal As Integer = 0</p><p> Dim totalMod As Integer = 0</p><p> Dim maxStat As Integer = 0</p><p></p><p> For i As Integer = 1 To 6</p><p> 'roll 4d6, drop the lowest</p><p> rollValue = 0</p><p> diceRslts.Clear()</p><p></p><p> For d As Integer = 0 To 3</p><p> diceRslts.Add(rnd.Next(1, 7))</p><p> Next</p><p></p><p> diceRslts.Sort()</p><p></p><p> For d As Integer = 1 To 3</p><p> rollValue += diceRslts(d)</p><p> Next</p><p></p><p> 'get point value, adjust total modifier</p><p> Select Case rollValue</p><p> Case 3</p><p> totalMod += -4</p><p> charPoints += 0</p><p> Case 4</p><p> totalMod += -3</p><p> charPoints += 0</p><p> Case 5</p><p> totalMod += -3</p><p> charPoints += 0</p><p> Case 6</p><p> totalMod += -2</p><p> charPoints += 0</p><p> Case 7</p><p> totalMod += -2</p><p> charPoints += 0</p><p> Case 8</p><p> totalMod += -1</p><p> charPoints += 0</p><p> Case 9</p><p> totalMod += -1</p><p> charPoints += 1</p><p> Case 10</p><p> totalMod += 0</p><p> charPoints += 2</p><p> Case 11</p><p> totalMod += 0</p><p> charPoints += 3</p><p> Case 12</p><p> totalMod += 1</p><p> charPoints += 4</p><p> Case 13</p><p> totalMod += 1</p><p> charPoints += 5</p><p> Case 14</p><p> charPoints += 6</p><p> totalMod += 2</p><p> Case 15</p><p> charPoints += 8</p><p> totalMod += 2</p><p> Case 16</p><p> charPoints += 10</p><p> totalMod += 3</p><p> Case 17</p><p> charPoints += 13</p><p> totalMod += 3</p><p> Case 18</p><p> charPoints += 16</p><p> totalMod += 4</p><p> End Select</p><p></p><p> maxStat = Math.Max(maxStat, rollValue)</p><p> Next</p><p></p><p> If totalMod > 0 AndAlso maxStat > 13 Then</p><p> Return charPoints</p><p> Else</p><p> Return RollCharacter(rnd)</p><p> End If</p><p></p><p> End Function</p><p>[/code][/sblock]</p></blockquote><p></p>
[QUOTE="drothgery, post: 2187697, member: 360"] My VB.NET Monte Carlo attempt is coming with around 30.9, a little higher than most of you got, though I'm playing with the VS.NET 2005 Beta 2 compilers, and this code uses some new features, so I'm wondering if I'm making any mistakes... [sblock][code] Private Sub GoBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoBtn.Click Dim iterationsCount As Integer Dim totalPoints As Long = 0 Dim avgPoints As Double If Integer.TryParse(Me.NumTb.Text, iterationsCount) Then Dim rnd As New System.Random For i As Integer = 0 To iterationsCount totalPoints += RollCharacter(rnd) Next avgPoints = totalPoints / iterationsCount RsltsLbl.Text = avgPoints.ToString End If End Sub Private Function RollCharacter(ByVal rnd As Random) As Integer Dim charPoints As Integer = 0 Dim diceRslts As New List(Of Integer) Dim rollValue As Integer Dim maxVal As Integer = 0 Dim totalMod As Integer = 0 Dim maxStat As Integer = 0 For i As Integer = 1 To 6 'roll 4d6, drop the lowest rollValue = 0 diceRslts.Clear() For d As Integer = 0 To 3 diceRslts.Add(rnd.Next(1, 7)) Next diceRslts.Sort() For d As Integer = 1 To 3 rollValue += diceRslts(d) Next 'get point value, adjust total modifier Select Case rollValue Case 3 totalMod += -4 charPoints += 0 Case 4 totalMod += -3 charPoints += 0 Case 5 totalMod += -3 charPoints += 0 Case 6 totalMod += -2 charPoints += 0 Case 7 totalMod += -2 charPoints += 0 Case 8 totalMod += -1 charPoints += 0 Case 9 totalMod += -1 charPoints += 1 Case 10 totalMod += 0 charPoints += 2 Case 11 totalMod += 0 charPoints += 3 Case 12 totalMod += 1 charPoints += 4 Case 13 totalMod += 1 charPoints += 5 Case 14 charPoints += 6 totalMod += 2 Case 15 charPoints += 8 totalMod += 2 Case 16 charPoints += 10 totalMod += 3 Case 17 charPoints += 13 totalMod += 3 Case 18 charPoints += 16 totalMod += 4 End Select maxStat = Math.Max(maxStat, rollValue) Next If totalMod > 0 AndAlso maxStat > 13 Then Return charPoints Else Return RollCharacter(rnd) End If End Function [/code][/sblock] [/QUOTE]
Insert quotes…
Verification
Post reply
Community
General Tabletop Discussion
*Pathfinder & Starfinder
Probability in Char. Gen.
Top