Discussion:
MS Bug or MSDN typo??
(too old to reply)
Smudge
2008-03-14 16:36:01 UTC
Permalink
The Rnd() Function doesn't appear to always work as it should (according to
the documentation / MSDN info for the Rnd() Function):

{Begin Excerpt from VS 2008 documentation}
"
To produce random integers in a given range, use the following formula.

Visual Basic :
randomvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() + lowerbound))




Here, upperbound is the highest number in the range, and lowerbound is the
lowest number in the range.

"
{End Excerpt from VS 2008 documentation}

Sounds straight forward enough, however the following VB code demonstrates
that the Rnd() function does not always behave as it should:



''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim upperbound As Integer = 254
Dim lowerbound As Integer = 128
Dim randomvalue As Integer

Dim intX As Integer

Randomize()
For intX = 0 To 100000000

randomvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() +
lowerbound))

If randomvalue > upperbound Then Console.WriteLine("UPPER BOUND
EXCEEDED!!!: randomvalue=" & randomvalue & " But upperbound=" & upperbound)

Next

Console.WriteLine("Finished!")

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

The above code writes a a message to the console whenever the Rnd() function
returns a randomvalue that is greater than the upperbound specified (as per
the documentation).
On running this code I see that there are instances where thr Rnd function
does that.

I would be interested to see if other people's computers produce the same
results - it seems that they certainly should!

So is this a bug in Rnd() or is the VS/MSDN documentation wrong?
.

Many thanks.
Robert Morley
2008-03-14 17:59:57 UTC
Permalink
This group is for VB6 and below. For (possible) VS2008 bugs, you need to
post to a group with "dotnet" in the name. At a quick glance, it doesn't
look like they have a group set up specifically for bugs, so I'd suggest
just posting in microsoft.public.dotnet.langauges.vb and see where that gets
you.



Rob
Post by Smudge
The Rnd() Function doesn't appear to always work as it should (according to
{Begin Excerpt from VS 2008 documentation}
"
To produce random integers in a given range, use the following formula.
randomvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() + lowerbound))
Here, upperbound is the highest number in the range, and lowerbound is the
lowest number in the range.
"
{End Excerpt from VS 2008 documentation}
Sounds straight forward enough, however the following VB code demonstrates
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim upperbound As Integer = 254
Dim lowerbound As Integer = 128
Dim randomvalue As Integer
Dim intX As Integer
Randomize()
For intX = 0 To 100000000
randomvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() + lowerbound))
If randomvalue > upperbound Then Console.WriteLine("UPPER BOUND
EXCEEDED!!!: randomvalue=" & randomvalue & " But upperbound=" & upperbound)
Next
Console.WriteLine("Finished!")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
The above code writes a a message to the console whenever the Rnd() function
returns a randomvalue that is greater than the upperbound specified (as per
the documentation).
On running this code I see that there are instances where thr Rnd function
does that.
I would be interested to see if other people's computers produce the same
results - it seems that they certainly should!
So is this a bug in Rnd() or is the VS/MSDN documentation wrong?
..
Many thanks.
NeilH
2008-03-17 08:02:42 UTC
Permalink
I thought that "dotnet" was so good that bugs could not exist!!!!
Post by Robert Morley
This group is for VB6 and below. For (possible) VS2008 bugs, you need to
post to a group with "dotnet" in the name. At a quick glance, it doesn't
look like they have a group set up specifically for bugs, so I'd suggest
just posting in microsoft.public.dotnet.langauges.vb and see where that gets
you.
Rob
Post by Smudge
The Rnd() Function doesn't appear to always work as it should (according to
{Begin Excerpt from VS 2008 documentation}
"
To produce random integers in a given range, use the following formula.
randomvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() + lowerbound))
Here, upperbound is the highest number in the range, and lowerbound is the
lowest number in the range.
"
{End Excerpt from VS 2008 documentation}
Sounds straight forward enough, however the following VB code demonstrates
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Post by Robert Morley
Post by Smudge
Dim upperbound As Integer = 254
Dim lowerbound As Integer = 128
Dim randomvalue As Integer
Dim intX As Integer
Randomize()
For intX = 0 To 100000000
randomvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() +
lowerbound))
If randomvalue > upperbound Then Console.WriteLine("UPPER BOUND
EXCEEDED!!!: randomvalue=" & randomvalue & " But upperbound=" & upperbound)
Next
Console.WriteLine("Finished!")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Post by Robert Morley
Post by Smudge
The above code writes a a message to the console whenever the Rnd() function
returns a randomvalue that is greater than the upperbound specified (as per
the documentation).
On running this code I see that there are instances where thr Rnd function
does that.
I would be interested to see if other people's computers produce the same
results - it seems that they certainly should!
So is this a bug in Rnd() or is the VS/MSDN documentation wrong?
..
Many thanks.
Loading...