https://github.com/lukencode/randomchoice
An simple library for making those hard (well just random) choices
https://github.com/lukencode/randomchoice
Last synced: 9 months ago
JSON representation
An simple library for making those hard (well just random) choices
- Host: GitHub
- URL: https://github.com/lukencode/randomchoice
- Owner: lukencode
- Created: 2011-08-07T13:35:32.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-09-02T08:24:00.000Z (over 14 years ago)
- Last Synced: 2025-04-05T17:51:08.569Z (10 months ago)
- Language: C#
- Homepage:
- Size: 102 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
A little helper library that given an (optionaly weighted) list of methods chooses one at random. Useful if you are making a game or something I guess.
```csharp
//add actions to the selector
var selector = RandomSelector
.AddAction(() => { doSomething(); })
.AddAction(() => { doSomeOtherThing(); });
selector.Choose(); //randomly picks an action to run
```
You can also optionally weight each action.
```csharp
//add actions to the selector (must add up to 1.0)
var selctor = RandomSelector
.AddAction(0.7, () => { probablyDoThis(); })
.AddAction(0.2, () => { maybeDoThis(); })
.AddAction(0.1, () => { smallChanceOfThis(); });
selector.Choose(); //randomly picks an action to run
```