WeightedRandom
Unity library for evaluating generic biased randomized results.
Install / Use
/learn @mert-dev-acc/WeightedRandomREADME
Weighted Randomizer for Unity
Allows you to get generic biased random selections depending on provided weight.
Best part of this randomizer is, it doesn't require to provide 100% total. It auto-calculates weights regarding to your weights.
So you can pass _Add->80%-Tremors Add->70%-Zombies in the same total.
Usage
Simple example:
WeightedRandom<Monsters> rnd = new WeightedRandom<Monsters>();
rnd.Add(new Ghost(),0.5f);
rnd.Add(new Zombie(),0.3f);
rnd.Next(); //This will return a biased random result.
Alternative parameters
WeightedRandom uses System.Random and FairBiased algorithm by default.
You can choose custom options on the constructor.
WeightAlgorithm
There are two algorithms right now.
- UnfairBiased: Provides a larger probability scale but results can be less predictable.
- FairBiased: Provides a steady bias and therefor more predictable results.
Weight Providers
Weight providers are basically random api's which have provided by Unity and C#(System) libraries.
- SystemRandomProvider: Uses System.Random implementation
- UnityEngineRandomProvider: Uses UnityEngine.Random.Range implementation
- UnityMathematicsRandomProvider: Uses Unity's new SIMD math library with Unity.Random implementation
TO-DO
- AddRange for multiple queries at once.
- GetInstance() implementation on other providers with T where:class
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.7kCommit, push, and open a PR
