6 Replies - 2002 Views - Last Post: 01 February 2013 - 12:40 AM Rate Topic: -----

#1 saint1000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-January 13

random number generator set for 1-4. but never picks 4

Posted 22 January 2013 - 10:56 PM

Dim rndnumber As Random
Dim number As Integer
rndnumber = New Random
number = rndnumber.Next(1, 4)
Form2.Label2.Text = number.ToString

random number generator. should pick numbers between 1 and 4. dont care if numbers repeat. just ran this 20 times and it never pick the number 4. i retried another 20 and still no number 4. will randomly pick between 1 and 3. any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: random number generator set for 1-4. but never picks 4

#2 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

Re: random number generator set for 1-4. but never picks 4

Posted 22 January 2013 - 11:16 PM

Quote

number = rndnumber.Next(1, 4)


USE INSTEAD OF ABOVE:

number = Int(1 + Rnd() * 4)


I ALSO SUGEST YOU TO USE [CODE] TAGS FOR WRITTING UR CODE

This post has been edited by kai_itz me: 22 January 2013 - 11:18 PM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3729
  • View blog
  • Posts: 13,019
  • Joined: 12-December 12

Re: random number generator set for 1-4. but never picks 4

Posted 23 January 2013 - 01:06 AM

Random.Next Method:

Quote

Return Value
Type: System.Int32
A 32-bit signed integer greater than or equal to minValue and less than maxValue; that is, the range of return values includes minValue but not maxValue. If minValue equals maxValue, minValue is returned.


MSDN

Looks like VB.NET
Was This Post Helpful? 0
  • +
  • -

#4 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

Re: random number generator set for 1-4. but never picks 4

Posted 23 January 2013 - 02:14 AM

i just saw andrew post and
i want to tell you that Rnd() is a function in vb.net to generate random numbers.



dim number = Int(1 + Rnd() * 4) 

This post has been edited by kai_itz me: 23 January 2013 - 02:19 AM

Was This Post Helpful? 0
  • +
  • -

#5 saint1000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 22-January 13

Re: random number generator set for 1-4. but never picks 4

Posted 23 January 2013 - 04:18 AM

thank you
Was This Post Helpful? 0
  • +
  • -

#6 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: random number generator set for 1-4. but never picks 4

Posted 31 January 2013 - 11:31 PM

Saint, please read http://www.dreaminco...his-is-old-vb6/ .
Was This Post Helpful? 0
  • +
  • -

#7 rakesh vish  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-January 13

Re: random number generator set for 1-4. but never picks 4

Posted 01 February 2013 - 12:40 AM

Dim rndnumber As Random
Dim number As Integer
rndnumber = New Random
number = rndnumber.Next(1, 4)
Form2.Label2.Text = number.ToString
==========================================================================================================================

change your below line of code :-
rndnumber.Next(1, 4)
with
rndnumber.Next(1, 5)
It will run surely without any bug ......................
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1