VB.net - random numbers

Soldato
Joined
8 Oct 2005
Posts
4,184
Location
Midlands, UK
Hi,

I'm using the below to generate a random number:

Code:
Dim randomSpeed as Random
someobject(3).speed = randomSpeed.Next(5, 11)

As the random number seems to be taking integer values only, is there a way to a make a more random number between 5 and 10? Its hard to explain, but as there are only 4 objects moving on the screen at once, miore often than not all objects take a very similar speed, making the game very easy.

Has anyone got a method to create a random number for each object i draw, from the "someobject(3) array.

Thanks
 
Code:
(randomSpeed.NextDouble() * 5) + 5

Random.NextDouble() produces a number greater than or equal to 0 and less than 1, so you need to multiply by 5 to increase the range to 0 - 4.9r and then add 5 to make it 5 - 9.9r :)
 
Last edited:
Inquisitor said:
Code:
(randomSpeed.NextDouble() * 5) + 5

Random.NextDouble() produces a number greater than or equal to 0 and less than 1, so you need to multiply by 5 to increase the range to 0 - 4.9r and then add 5 to make it 5 - 9.9r :)


ah nice idea. Ill try that one out now :)
 
Back
Top Bottom