Re: Random Numbers are NOT random !!!
From: Gerry O'Brien [MVP] (gerry)
Date: 09/29/04
- Next message: Ken Tucker [MVP]: "Re: Add in for MS office"
- Previous message: Gerry O'Brien [MVP]: "Re: Cannot Get VB.Net Standard to connect to a MSAccess Database."
- In reply to: mark4asp: "Random Numbers are NOT random !!!"
- Next in thread: Larry Serflaten: "Re: Random Numbers are NOT random !!!"
- Reply: Larry Serflaten: "Re: Random Numbers are NOT random !!!"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 29 Sep 2004 08:51:22 -0300
You must call Randomize first in order to get a random seed value.
Rnd will always return the same numbers every time you run it unless you
provide it a different seed to start with each time. That is what Randomize
does. Just place it as the first line in your method before Rnd().
You can use Randomize(numbero of your choosing), or you can simply call
Randomize and it will pull the seed value from the system timer.
Have fun!
-- Gerry O'Brien [MVP] Visual Basic .NET(VB.NET) "mark4asp" <mark4asp#killspam#@ntlworld.com> wrote in message news:qk5ll0de8ah1l7ckvnk41kplskfaqpjhlc@4ax.com... > The result of RandList() is a list of numbers which are all the SAME. > > Changing the d() function to the one which is commented out has no > effect (of course). > > How can I get the function [ d() ] to return a different random number > each time? > > Function RandList() > Dim str As String = "" > Dim i As Integer > For i = 1 To 100 > str += d(10).toString() & ", " > Next > Return str > End Function > > Function d(ByVal high) As Integer > Return New System.Random().Next(1, high+1) > End Function > > ' Function d(num As Integer) > ' Dim RanNum As New Random > ' Return RanNum.Next(1, num+1) > ' End Function >
- Next message: Ken Tucker [MVP]: "Re: Add in for MS office"
- Previous message: Gerry O'Brien [MVP]: "Re: Cannot Get VB.Net Standard to connect to a MSAccess Database."
- In reply to: mark4asp: "Random Numbers are NOT random !!!"
- Next in thread: Larry Serflaten: "Re: Random Numbers are NOT random !!!"
- Reply: Larry Serflaten: "Re: Random Numbers are NOT random !!!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|