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

Page 1 of 1

## 6 Replies - 2293 Views - Last Post: 01 February 2013 - 12:40 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=308778&amp;s=90a68c2cfecb0c6528df60a0e136e81a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 saint1000

• New D.I.C Head

Reputation: 0
• 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

Reputation: 28
• 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

### #3 andrewsw

• I'm not here to twist your niblets

Reputation: 4231
• Posts: 15,449
• 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

### #4 kai_itz me

Reputation: 28
• 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

### #5 saint1000

• New D.I.C Head

Reputation: 0
• 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

### #6 BobRodes

• Lovable Curmudgeon

Reputation: 579
• Posts: 2,995
• Joined: 19-May 09

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

Posted 31 January 2013 - 11:31 PM

### #7 rakesh vish

• New D.I.C Head

Reputation: 0
• 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 ......................