i am trying to create a messagebox which brings up four random percentages which add unto 100%, i can create the messagebox with

messagebox.show ("")

but have no idea how to create the random percentages, can anyone please help me with this.

Edited by mike_2000_17: Fixed formatting

6 Years
Discussion Span
Last Post by pritesh2010

I was thinking imagine it as a chunk of 100 x's


Now just pick four randoms positions each one greater than the previous.

This will work as long as the first one isn't something like position 99.

Or, you could do something which isn't really random but...

1) random (0,25)
2) random (0,25)
3) random (0,25)
4) Add all three together then subtract from 100 to get the last percentage.

Edited by iamthwee: n/a


You could try this:

Dim randomNumber As Integer
randomNumber = RandomClass.Next(0,100) // creates a random number from 0 - 100

messagebox.show(randomNumber , "%") ' ex of output would be "28%", if it doesn't work, try
' messagebox.show(randomNumber + "%") I just took a python class in school so i forgot 
' which is the correct concatenation for vb.net

Edited by Patplays852: n/a


hey You can use

The following code returns a random number: 

Dim num As Integer = random.Next()

The following code returns a random number less than 1000. 

Dim num As Integer = random.Next(1000) 

The following code returns a random number between min and max: 

Private Function RandomNumber(min As Integer, max As Integer) As Integer 
   Dim random As New Random() 
   Return random.Next(min, max) 
End Function 'RandomNumber

try both the method

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.