[Solved]Random number help

Posts 1–6 of 6 · Page 1 of 1
[Solved]Random number help
I created two different random numbers but both of them always generate the same number, and I don't know whats going on, any help would be appreciated. My VB teacher at school helped me with this but I forgot what he did.
make sure the 1st number is SMALLER than the 2nd number by at least two.
2 things,

One is, What are you talking about Mneep?

Second,

Problem with VB is when you generate a random number, you are generating Psuedo Random, Meaning both numbers will be the same, and both numbers will generate the same numbers from start to finish, no real random

To avoid this

part one :

Each number should have different Values

Rnd(1) * 4 + 1
Rnd(1) * 4 + 2

The pplus at the end will change the values and make them different, Now how to prvent the Psuedo Random outcome is alittle more tricky,

One way is to use a label that is attached to a timer,

Timer1 event

Label1.text = label1.text + 1


then you call your random numbers elsewhere

rnd(1) * 5 + label1.text
rnd(1) * 4 + Label1.text


or (and my favorite) is to generate a number based off your current system.diagnostics
Cpu speed, that number is always fluctuating allowing more random numbers


Hope this helps
Quote Originally Posted by NextGen1 View Post
2 things,

One is, What are you talking about Mneep?

Second,

Problem with VB is when you generate a random number, you are generating Psuedo Random, Meaning both numbers will be the same, and both numbers will generate the same numbers from start to finish, no real random

To avoid this

part one :

Each number should have different Values

Rnd(1) * 4 + 1
Rnd(1) * 4 + 2

The pplus at the end will change the values and make them different, Now how to prvent the Psuedo Random outcome is alittle more tricky,

One way is to use a label that is attached to a timer,

Timer1 event

Label1.text = label1.text + 1


then you call your random numbers elsewhere

rnd(1) * 5 + label1.text
rnd(1) * 4 + Label1.text


or (and my favorite) is to generate a number based off your current system.diagnostics
Cpu speed, that number is always fluctuating allowing more random numbers


Hope this helps
Oh wow NextGen. I didn't cop a word of that.. Except the bit about the plus =P. Your such a brainiac =P
Here is another solution:

Dim x As New Random
'Generates a random number between 1 to 100
x.Next(1, 100)

Hope this helps !!
Code:
 Private Function Randomizer(ByVal Startn As Integer, ByVal Endn As Integer) As Integer
        Dim nRandom As Integer
        Randomize()
        nRandom = iStart + (Rnd() * (Endn - Startn))
        Return nRandom
    End Function


Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us