mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Updated random interface further.
This commit is contained in:
@@ -76,21 +76,27 @@ fn uint128 Random.next_uint128(&self)
|
||||
|
||||
/**
|
||||
* @param [&inout] self
|
||||
* @require types::is_numerical($typeof(seed))
|
||||
**/
|
||||
fn void Random.set_seed(&self, long seed)
|
||||
macro void Random.seed_random(&self, seed)
|
||||
{
|
||||
self.fns.seed_fn(self, &&bitcast(seed, char[8])) @inline;
|
||||
self.fns.seed_fn(self, @as_char_view(seed)) @inline;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param [&inout] random
|
||||
* @param [in] seed
|
||||
**/
|
||||
fn void Random.set_seeds(&random, char[] seed)
|
||||
fn void Random.set_seed(&random, char[] seed)
|
||||
{
|
||||
random.fns.seed_fn(random, seed);
|
||||
}
|
||||
|
||||
fn int Random.next(&random, int max)
|
||||
{
|
||||
return (int)(random.next_double() * max);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param [&inout] self
|
||||
**/
|
||||
@@ -105,7 +111,6 @@ fn float Random.next_float(&self)
|
||||
return val / (float)(1 << 24);
|
||||
}
|
||||
|
||||
|
||||
fn double Random.next_double(&self)
|
||||
{
|
||||
ulong val = self.next_long() & (1UL << 53 - 1);
|
||||
|
||||
@@ -7,7 +7,7 @@ const MUL_LCG64 @local = 0xd1342543de82ef95;
|
||||
macro make_seed($Type, char[] input)
|
||||
{
|
||||
$Type return_value;
|
||||
seeder(input, @to_byte_view(return_value));
|
||||
seeder(input, @as_char_view(return_value));
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user