Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
rt.util.random: add attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jun 28, 2016
1 parent 6251718 commit 22f7010
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/rt/util/random.d
Expand Up @@ -8,35 +8,38 @@ module rt.util.random;

struct Rand48
{
nothrow:
private ulong rng_state;

@safe @nogc nothrow:

void defaultSeed()
{
import ctime = core.stdc.time : time;
seed(cast(uint)ctime.time(null));
}

pure:

void seed(uint seedval)
{
assert(seedval);
rng_state = cast(ulong)seedval << 16 | 0x330e;
popFront();
}

auto opCall() @nogc
auto opCall()
{
auto result = front;
popFront();
return result;
}

@property uint front() @nogc
@property uint front()
{
return cast(uint)(rng_state >> 16);
}

void popFront() @nogc
void popFront()
{
immutable ulong a = 25214903917;
immutable ulong c = 11;
Expand Down

0 comments on commit 22f7010

Please sign in to comment.