Add Bool:random(p=0.5)
This commit is contained in:
parent
0f1c475bb4
commit
04714e00d7
@ -40,6 +40,11 @@ public Bool_t Bool$from_text(CORD text, bool *success)
|
||||
}
|
||||
}
|
||||
|
||||
public Bool_t Bool$random(double p)
|
||||
{
|
||||
return (drand48() < p);
|
||||
}
|
||||
|
||||
public const TypeInfo $Bool = {
|
||||
.size=sizeof(bool),
|
||||
.align=__alignof__(bool),
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
CORD Bool$as_text(const bool *b, bool colorize, const TypeInfo *type);
|
||||
bool Bool$from_text(CORD text, bool *success);
|
||||
Bool_t Bool$random(double p);
|
||||
|
||||
extern const TypeInfo $Bool;
|
||||
|
||||
|
@ -85,6 +85,7 @@ env_t *new_compilation_unit(CORD *libname)
|
||||
{"Memory", Type(MemoryType), "Memory_t", "$Memory", {}},
|
||||
{"Bool", Type(BoolType), "Bool_t", "$Bool", TypedArray(ns_entry_t,
|
||||
{"from_text", "Bool$from_text", "func(text:Text, success=!&Bool)->Bool"},
|
||||
{"random", "Bool$random", "func(p=0.5)->Bool"},
|
||||
)},
|
||||
{"Int", Type(IntType, .bits=0), "Int_t", "$Int", TypedArray(ns_entry_t,
|
||||
{"format", "Int$format", "func(i:Int, digits=0)->Text"},
|
||||
|
Loading…
Reference in New Issue
Block a user