Wolfe Deckard Posted February 2, 2019 Share Posted February 2, 2019 Hi there Im looking for a way to create a dice script that will generate a number between -4 and +4 and including 0 so a range of -4,-3.-2,-1,0,1,2,3,4. Any input will be greatly appreciated. Thanks Link to comment Share on other sites More sharing options...
Innula Zenovka Posted February 2, 2019 Share Posted February 2, 2019 This might be one way to do it: integer n = (integer)llFrand(10.0); //generate a float between 0.0 and 9.999....99. Converting it to an integer rounds down, so you have an integer between 0 and 9 integer iRandom = -4 + n; 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 2, 2019 Share Posted February 2, 2019 (edited) Or, written another way integer RndX = 4 - (integer) llFrand(9.0); Edit: Thanks, Innula Edited February 2, 2019 by Rolig Loon Link to comment Share on other sites More sharing options...
Innula Zenovka Posted February 2, 2019 Share Posted February 2, 2019 (edited) I think you mean (integer) llFrand(9.0) llFrand(10.0); Rolig. The die has 9 faces, including the 0. Edited February 2, 2019 by Innula Zenovka Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 2, 2019 Share Posted February 2, 2019 Right you are. Fixed..... ^^ 1 Link to comment Share on other sites More sharing options...
Xiija Posted February 2, 2019 Share Posted February 2, 2019 just curious, why does 4 minus 0 = -4? lol i would have thought you would need to do integer RndX = -4 + (integer) llFrand(9.0); Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted February 2, 2019 Share Posted February 2, 2019 (edited) 5 minutes ago, Xiija said: just curious, why does 4 minus 0 = -4? lol i would have thought you would need to do integer RndX = -4 + (integer) llFrand(9.0); "-4 + rand" is mathematically equivalent to "4 - rand" Where did you get 4 - 0 = -4? Edited February 2, 2019 by Wulfie Reanimator 1 Link to comment Share on other sites More sharing options...
Fionalein Posted February 2, 2019 Share Posted February 2, 2019 1 minute ago, Wulfie Reanimator said: "-4 + rand" is mathematically equivalent to "4 - rand" Isn't it equal to "+rand -4" instead? Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted February 2, 2019 Share Posted February 2, 2019 Just now, Fionalein said: Isn't it equal to "+rand -4" instead? as well* Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 2, 2019 Share Posted February 2, 2019 (edited) 11 hours ago, Rolig Loon said: integer RndX = 4 - (integer) llFrand(9.0); So ..... if (integer)llFrand(9.0) == 0, RndX = 4 if (integer)llFrand(9.0) == 1, RndX = 3 if (integer)llFrand(9.0) == 2, RndX = 2 if (integer)llFrand(9.0) == 3, RndX = 1 if (integer)llFrand(9.0) == 4, RndX = 0 if (integer)llFrand(9.0) == 5, RndX = -1 if (integer)llFrand(9.0) == 6, RndX = -2 if (integer)llFrand(9.0) == 7, RndX = -3 if (integer)llFrand(9.0) == 8, RndX = -4 And yes, it doesn't make any difference which way you do the math. Innula's way and mine are the same. I was just trying to show the OP an alternate way of writing the same thing. Edited February 2, 2019 by Rolig Loon Link to comment Share on other sites More sharing options...
Innula Zenovka Posted February 2, 2019 Share Posted February 2, 2019 11 hours ago, Innula Zenovka said: I think you mean (integer) llFrand(9.0); Rolig. The die has 9 faces, including the 0. Akk.. I meant llFrand(10.0) (as in my example)! Sorry all. Link to comment Share on other sites More sharing options...
Wolfe Deckard Posted February 3, 2019 Author Share Posted February 3, 2019 thanks, everyone! Link to comment Share on other sites More sharing options...
Whirly Fizzle Posted February 3, 2019 Share Posted February 3, 2019 I don't know if this is any use to you as well, but Firestorm Viewer includes a dice feature - see https://wiki.phoenixviewer.com/fs_dice 1 Link to comment Share on other sites More sharing options...
chibiusa Ling Posted February 3, 2019 Share Posted February 3, 2019 54 minutes ago, Whirly Fizzle said: I don't know if this is any use to you as well, but Firestorm Viewer includes a dice feature - see https://wiki.phoenixviewer.com/fs_dice You learn something new every day, I had no idea that was even there Link to comment Share on other sites More sharing options...
Xiija Posted February 3, 2019 Share Posted February 3, 2019 heh, sry, was just codeblind.. dunno, i finally get it.. 4 - 8 = -4! Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now