## ProblemYou need to generate a sequence of pseudorandom numbers with a normal distribution, given the distribution's mean and standard deviation. ## SolutionSample code folder: Chapter 06\RepeatRandom The GetNextNormal(mean, stdDev) ## DiscussionThe following code creates a new instance of the The Dim result As New System.Text.StringBuilder Dim generator As New BetterRandom Dim mean As Double = 100 Dim stdDev As Double = 10 Dim counter As Integer result.Append("Normal distribution randoms with mean ") result.AppendLine(mean & " and standard deviation " & stdDev) result.AppendLine() For counter = 1 To 20 ' ----- Add one random number. result.Append(generator.GetNextNormal(mean, stdDev)) If ((counter Mod 3) = 0) Then ' ----- Group on distinct lines periodically. result.AppendLine() Else result.Append(", ") End If Next counter MsgBox(result.ToString()) Figure 6-29 shows the results of generating the 20 pseudorandom double-precision normal-distribution numbers. ## Figure 6-29. Pseudorandom normally distributed numbers generated by the BetterRandom object## See AlsoRecipe 6.26 shows the full code for the There are many good references on the Web to learn more about random number generation (see, for example, http://random.mat.sbg.ac.at). |

Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))

ISBN: 0596101775

EAN: 2147483647

EAN: 2147483647

Year: 2006

Pages: 400

Pages: 400

Authors: Tim Patrick, John Craig

Similar book on Amazon

flylib.com © 2008-2017.

If you may any questions please contact us: flylib@qtcs.net

If you may any questions please contact us: flylib@qtcs.net