Rounding Problems in VB6

Started by
0 comments, last by gamechampionx 20 years, 5 months ago
In VB6, I''m using the line: random_num = (Rnd * (enemy_muscle * 10 + 10) + 1) \ 1 to randomize a number from 1 to 10 times the enemy_muscle variable. The problem occurrs when Rnd is something like 0.99... What happens is that the compiler rounds it up to 10, so results are one more than they should be. How can I fix this?
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
Advertisement
I used this (straight from my old VB DX engine):

Public Function RandomNumber(ByVal Min As Long, ByVal Max As Long, Optional ByVal RandomizeCounterStart = 1000) As Long    ' Returns a random number between the Min and Max values.    ' Every thousand random numbers, it randomizes the random number generator.    Static RandomizeCounter As Integer        RandomizeCounter = RandomizeCounter - 1    If RandomizeCounter <= 0 Then        Randomize Timer        RandomizeCounter = RandomizeCounterStart    End If        RandomNumber = Int(Rnd * ((Max + 1) - Min)) + MinEnd Function


[EDIT] You don't even have to randomize the random number generator when your program starts if you use that.

[edited by - Rob Loach on November 16, 2003 12:13:47 AM]
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement