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.

Recommended Answers

All 3 Replies

Member Avatar for iamthwee

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

[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]


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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.