SkillAgentSearch skills...

Aliasmethod

A C++ implementation of Walker's Alias Method for quickly sampling from an array with a given probability distribution

Install / Use

/learn @m-ochi/Aliasmethod
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

WalkerMethod

Walker's Alias Method is an O(1) algorithm for selecting elements from an array given a weighted distribution.

For example, let's say you want to return :win 60% of the time, :lose 20% of the time, and :tie 20% of the time. You could fill an array with 6 examples of :win and 2 examples each of :lose and :tie, then pick a random element. You could also use ranges, picking a random number between 0.0 and 1.0 and returning :win when the number is below 0.6, :lose if the number is below 0.8, and :tie otherwise. But, these algorithms are still O(n). You can do better by using a heap or binary search tree, but Walker's Alias Method is better still, with a constant runtime once an O(n) pre-computation phase has completed.

how to use

  • if you need main function, please comment out there.
  • cmake .
  • make

Related Skills

View on GitHub
GitHub Stars10
CategoryDevelopment
Updated11mo ago
Forks2

Languages

C++

Security Score

67/100

Audited on May 11, 2025

No findings