Rnd Command

  • Thread starter Thread starter V Power
  • Start date Start date
V

V Power

Hi,

I have just been putting together a random number
generator to practice with VB .NET. The Rnd command on its
own works fine, however as soon as I add = 10 to the
string I get a return value of false. If i use the string
CStr(Int(Rnd() = 10)) I get a return value of 0.

What am I doing wrong - because the debugger seems to
think everything is fine.

Kind regards

Vicky
 
you are doing a boolean comparison

rnd() could be 5.3
is 5.3 = 10 ? --> false
cint(false) = 0
cstr(0) = "0"

i don't know w you want w the = 10 but thats not the way to do it

hope it helps

eric
 
Hi,

Well apprently that string was supposed to round the random
number to = say 7 rather than 0.708

CStr(Int(Rnd() = 10))

Hope that makes sense,

thanks for your answer Ive noted it :)

Vicky
 
that would be CStr(Int(Rnd() * 10)) :)


V Power said:
Hi,

Well apprently that string was supposed to round the random
number to = say 7 rather than 0.708

CStr(Int(Rnd() = 10))

Hope that makes sense,

thanks for your answer Ive noted it :)

Vicky
 
Yeah,
Ive just sat and re-read it all loads and suddenly my
vision celared :)
I wont be forgetting that in a hurry! :)

thankyou

Vicky
 
Hi,

I have just been putting together a random number
generator to practice with VB .NET. The Rnd command on its
own works fine, however as soon as I add = 10 to the


Any reason you're not using the Random class?

'Create an instance of the random class
Dim rand As New Random(Environment.TickCount)

'Generate 10 random integers between 1 and 100
For x As Integer = 0 To 99
Console.WriteLine(rand.Next(1,101).ToString)
Next

'Generate 10 random doubles between 0 and 1
For x As Integer = 0 To 99
Console.WriteLine(rand.NextDouble.ToString)
Next
 
Back
Top