-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
G3Kappa
committed
May 10, 2024
1 parent
ac49a98
commit 1cc7dbf
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Ergo.Runtime.BuiltIns; | ||
|
||
public sealed class Choose : BuiltIn | ||
{ | ||
public Random Rng { get; set; } = new Random(); | ||
private readonly Call CallInst = new(); | ||
|
||
public Choose() | ||
: base("", new("choose"), default, WellKnown.Modules.Meta) | ||
{ | ||
} | ||
|
||
public override ErgoVM.Op Compile() => vm => | ||
{ | ||
var arg = vm.Args[Rng.Next(vm.Arity)]; | ||
vm.Arity = 1; | ||
vm.SetArg(0, arg); | ||
CallInst.Compile()(vm); | ||
}; | ||
} |