[INC] alias method random
i needed a way the get a random idx from a array based on weights and i found this blog post by some random dude:
https://blog.bruce-hill.com/a-faster...-random-choice and ported the alias method to sourcepawn include: https://github.com/arthurdead/sm-plu...liasrandom.inc seems to work good enough for me: https://i.imgur.com/keVkgNy.png Code:
#include <sourcemod> |
Re: [INC] alias method random
Duck duck go my store jackpot plugin. I think mine is more efficient, and I doubt arraylists are necessary.
|
Re: [INC] alias method random
Quote:
-Perf test it whatever you are talking about and show results. -Why not contribute with the more efficient code so everyone benefits using this include. EDIT:I'v never used a weighting system tbh the blog was interesting, thanks for the include i will use it :) |
Re: [INC] alias method random
Quote:
Yeah, if you could submit the code, it would be really nice, since these funcs are not often seen here and they're very useful |
Re: [INC] alias method random
Quote:
|
Re: [INC] alias method random
I got an error at 'target.Push(i)' .
I guess in extreme cases, the result of "GetRandomFloat (-1.0,1.0) " can be 0.0, so the 'ArrayList target' will remain as "null",which can cause error when "target.Push(i)" Code:
ArrayList smalls = new ArrayList(2); I made a simple fix. Code:
if(weight == avg) |
All times are GMT -4. The time now is 04:15. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.