Simulating Dices; One dice.
Simulating dice is pretty simple function but it is needed often.
In this article, i try to give you everything you need to know for creating proper Dice function.
What we need…
At start, lets pretend you are creating a game where you need dice function.
Through whole game, you only need to roll d6 dice. d6 means normal 6 side dice wich is numbered from1 to 6.
…and how we can get it:
' first, we declare function that randomizes number and returns it. DECLARE Function DiceRoll(Sides AS Integer) AS Integer ' here is our simple dice function Function DiceRoll(Sides AS Integer) Return (INT(RND * Sides) + 1) END Function Randomize Timer DIM Dice AS Integer Dice = 6 ' normal d6 dice. DIM Wanted AS Integer Wanted = 3 ' this is value we try to get. ' and now we DO...LOOP until DiceRoll(Dice) returns wanted value (3) DO Loop Until DiceRoll(Dice) = Wanted