ItHadToComeToThis Posted December 30, 2022 Share Posted December 30, 2022 If you were fighting a boss and its dropped loot 1.4% of the time. What is the best way to code this so its accurate. I know I could do a random number of 100.0 and if its 1.4 then rez the object, but I feel that's not exactly what I'm after. Any advice? 1 Link to comment Share on other sites More sharing options...
animats Posted December 30, 2022 Share Posted December 30, 2022 See https://wiki.secondlife.com/wiki/LlFrand. llFrand(100.0) < 1.4 Note that the LSL random number generator is not random enough for either non-toy cryptographic key generation or gambling. Gameplay, fine. 2 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted December 30, 2022 Share Posted December 30, 2022 (edited) Just to provide another idea to try: if( (llHash(llGenerateKey())%1000)<14 ){...} is a more expensive alternative to llFrand that may or may not have minutely different randomness characteristics. ETA: see below, quick fix is: if( (llAbs(llHash(llGenerateKey()))%1000)<14 ){...} Edited December 31, 2022 by Quistess Alpha Link to comment Share on other sites More sharing options...
Lucia Nightfire Posted December 31, 2022 Share Posted December 31, 2022 13 hours ago, Quistess Alpha said: Just to provide another idea to try: if( (llHash(llGenerateKey())%1000)<14 ){...} is a more expensive alternative to llFrand that may or may not have minutely different randomness characteristics. llHash() can return negatives and modulo can handle negatives, so that return range would be -999 to 999 instead of 0 to 999, favoring < 14 even more. 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted December 31, 2022 Share Posted December 31, 2022 (edited) 23 hours ago, ItHadToComeToThis said: I know I could do a random number [up to] 100.0 and if its [less than] 1.4 then rez the object, but I feel that's not exactly what I'm after. [corrections/ additions] Another (rather expensive) method would be to add 14 [1]'s and 1000-14 = 986 [0]'s to a list, llListRandomize() it and step through it, rezing if you pick a [1] from the list, re-randomizing after you hit the end. That would result in a different kind of random distribution. Quote list rezChance; integer indexRez; integer shouldIRez() { integer ret = llList2Integer(rezChance,indexRez++); if(indexRez==1000) { indexRez=0; rezChance = llListRandomize(rezChance); } return ret; } default { state_entry() { list one = [1]; list zero = [0]; integer n = 14; while(~--n) { rezChance+=one; } n = 986; while(~--n) { rezChance+=zero; } rezChance = llListRandomize(rezChance); } // testing analog for situation in which there is a chance ot rez: touch_start(integer n) { if(shouldIRez()) { llRezObject(...); } } } // Untested code, use with caution! Edited December 31, 2022 by Quistess Alpha Link to comment Share on other sites More sharing options...
ItHadToComeToThis Posted January 5, 2023 Author Share Posted January 5, 2023 Thank you for the responses, @Quistess Alpha that's quite interesting, I will give a test later when I am back at home 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