Shoutbox

It seems the tDice script hates 1. - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: It seems the tDice script hates 1. (/showthread.php?tid=89979)

It seems the tDice script hates 1. by Goomba on 03-30-2009 at 03:54 AM

I've been using the tDice script for a looong time now, and just now I have realized that it's rare that 1 is rolled. If you roll a series of die with 2 sides, it will most likely get 2, like this sequence I have rolled.

Throwing 20 Dices with 2 Sides each:
1. Dice: 2
2. Dice: 2
3. Dice: 2
4. Dice: 2
5. Dice: 2
6. Dice: 2
7. Dice: 2
8. Dice: 2
9. Dice: 2
10. Dice: 2
11. Dice: 2
12. Dice: 2
13. Dice: 2
14. Dice: 2
15. Dice: 2
16. Dice: 2
17. Dice: 2
18. Dice: 2
19. Dice: 1
20. Dice: 2

Now if you roll let's say, 1-4, you'll get something like this. (I JUST ROLLED THIS)

Throwing 20 Dices with 4 Sides each:
1. Dice: 4
2. Dice: 4
3. Dice: 3
4. Dice: 3
5. Dice: 4
6. Dice: 4
7. Dice: 4
8. Dice: 2
9. Dice: 4
10. Dice: 3
11. Dice: 3
12. Dice: 1
13. Dice: 2
14. Dice: 3
15. Dice: 4
16. Dice: 4
17. Dice: 2
18. Dice: 1
19. Dice: 3
20. Dice: 2

Only two 1s.

No, this is not just chance, I've done 10 die with 2 sides over 50 times, none of them had a majority of 1's, only 2's.

Is there any way to fix this script at all?


RE: It seems the tDice script hates 1. by prashker on 03-30-2009 at 04:23 AM

Import the following attachment.

I changed

Javascript code:
Result = Math.round((Math.random()*Sides)+1);

The round() method rounds a number to the nearest integer.

to

Javascript code:
Result = Math.floor((Math.random()*Sides)+1);

The floor() method returns the value of a number rounded DOWNWARDS to the nearest integer.

Now with your 2 tests it returns each more randomly.

Throwing 20 Dices with 2 Sides each:
1. Dice: 1
2. Dice: 1
3. Dice: 2
4. Dice: 1
5. Dice: 1
6. Dice: 1
7. Dice: 2
8. Dice: 1
9. Dice: 2
10. Dice: 1
11. Dice: 2
12. Dice: 2
13. Dice: 1
14. Dice: 1
15. Dice: 2
16. Dice: 1
17. Dice: 1
18. Dice: 2
19. Dice: 1
20. Dice: 1

Throwing 20 Dices with 4 Sides each:
1. Dice: 2
2. Dice: 4
3. Dice: 3
4. Dice: 1
5. Dice: 3
6. Dice: 1
7. Dice: 2
8. Dice: 3
9. Dice: 2
10. Dice: 1
11. Dice: 4
12. Dice: 1
13. Dice: 1
14. Dice: 3
15. Dice: 4
16. Dice: 1
17. Dice: 4
18. Dice: 3
19. Dice: 2
20. Dice: 2

Enjoy :)

RE: RE: It seems the tDice script hates 1. by Goomba on 03-30-2009 at 10:19 PM

THANKS!

You are quite the fellow.