Re: Random Numbers are NOT random !!!

From: Larry Serflaten (serflaten_at_usinternet.com)
Date: 09/29/04


Date: Wed, 29 Sep 2004 06:49:47 -0500


"mark4asp" <mark4asp#killspam#@ntlworld.com> wrote

>
> How can I get the function [ d() ] to return a different random number
> each time?
>

> Function d(ByVal high) As Integer
> Return New System.Random().Next(1, high+1)
> End Function

That random generator is just that, a generator. You need to
fire it up and pull out the random numbers. What you are doing
is starting up a whole lot of new generators. Since the generators
use the current time as their seed (when you provide no seed yourself)
and you are calling them all in a blink of an eye, they are all created
using the same seed.

What you need to do is to declare your generator at the module
level:

Private RandomGenerator As New Random

And use your routine to pull out the random numbers:

> Function d(ByVal high) As Integer
> Return RandomGenerator.Next(1, high+1)
> End Function

See if that helps

LFS



Relevant Pages

  • Re: Concurrent access to /dev/urandom
    ... no much of the time you can get away with useing a random number generator ... but if you pull enough numbers you will get collisions. ... And the other way is to make it so complicated that there are no obvious deficiencies. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Tuning Amps
    ... The multiple contact system is used in the New B-3, ... The keyclick generation system in the XK works great, ... Gets clickier when you pull more drawbars, ... to go from an 80s clean generator with no hum, ...
    (alt.guitar.amps)
  • Re: Tuning Amps
    ... Lord Valve wrote: ... in Cherry stinking up the next room. ... Gets clickier when you pull more drawbars, ... to go from an 80s clean generator with no hum, ...
    (alt.guitar.amps)
  • Re: Tuning Amps
    ... Lord Valve wrote: ... in Cherry stinking up the next room. ... Gets clickier when you pull more drawbars, ... to go from an 80s clean generator with no hum, ...
    (alt.guitar.amps)
  • Re: Tuning Amps
    ... The multiple contact system is used in the New B-3, ... The keyclick generation system in the XK works great, ... Gets clickier when you pull more drawbars, ... to go from an 80s clean generator with no hum, ...
    (alt.guitar.amps)