Dim randValue As Integer
Dim x As New Random
randValue = x.Next(1001)
The documentation on the Next method does not state the very important fact
that the value you pass as the maximum value the random class should return
(in this case 1001) is never reached. So, if you want to potentially get
back 1000, you must enter 1001.
"Efrain" <Efrain@discuss ions.microsoft. com> wrote in message
news:DCB1B99A-4B0A-452B-9D88-1282C509CDF7@mi crosoft.com...[color=blue]
> Can somebody help me out? I need the code to generate a random number
> between
> 1 and 100.[/color]
"Efrain" <Efrain@discuss ions.microsoft. com> wrote in message
news:DCB1B99A-4B0A-452B-9D88-1282C509CDF7@mi crosoft.com...[color=blue]
> Can somebody help me out? I need the code to generate a random number
> between
> 1 and 100.[/color]
Scott gave you VB code. Here's the C# equivalent.
Random myR = new Random();
int x = myR.Next(1,101) ;
The C++ code would depend on the type of project, i.e. the .NET Random class
would be appropriate in a .NET WinForms app, but not in a MFC app.
What language are you using?
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Scott M. <s-mar@nospam.nosp am> wrote:[color=blue]
> Dim randValue As Integer
> Dim x As New Random
> randValue = x.Next(1001)
>
> The documentation on the Next method does not state the very important fact
> that the value you pass as the maximum value the random class should return
> (in this case 1001) is never reached. So, if you want to potentially get
> back 1000, you must enter 1001.[/color]
However, the lower bound should be 0 here, so actually what's wanted is
Comment