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

Commit

Permalink
src/tinymt32.erl: add record fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
jj1bdx committed Feb 7, 2015
1 parent ab44a12 commit dd1f6ee
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/tinymt32.erl
Expand Up @@ -98,32 +98,38 @@

-spec next_state(intstate32()) -> intstate32().

next_state(R) ->
Y0 = R#intstate32.status3,
X0 = R#intstate32.status0
bxor R#intstate32.status1 bxor R#intstate32.status2,
next_state(#intstate32{
status0 = R0, status1 = R1,
status2 = R2, status3 = R3,
mat1 = M1, mat2 = M2, tmat = TM}) ->
Y0 = R3,
X0 = R0 bxor R1 bxor R2,
X1 = (X0 bxor (X0 bsl ?TINYMT32_SH0)) band ?TINYMT32_UINT32,
Y1 = Y0 bxor (Y0 bsr ?TINYMT32_SH0) bxor X1,
S0 = R#intstate32.status1,
S10 = R#intstate32.status2,
S0 = R1,
S10 = R2,
S20 = (X1 bxor (Y1 bsl ?TINYMT32_SH1)) band ?TINYMT32_UINT32,
S3 = Y1,
Y1M = (-(Y1 band 1)) band ?TINYMT32_UINT32,
S1 = S10 bxor (R#intstate32.mat1 band Y1M),
S2 = S20 bxor (R#intstate32.mat2 band Y1M),
R#intstate32{status0 = S0, status1 = S1, status2 = S2, status3 = S3}.
S1 = S10 bxor (M1 band Y1M),
S2 = S20 bxor (M2 band Y1M),
#intstate32{
status0 = S0, status1 = S1, status2 = S2, status3 = S3,
mat1 = M1, mat2 = M2, tmat = TM}.

%% @doc Generate 32bit unsigned integer from the TinyMT internal state.

-spec temper(intstate32()) -> uint32().

temper(R) ->
T0 = R#intstate32.status3,
T1 = (R#intstate32.status0 + (R#intstate32.status2 bsr ?TINYMT32_SH8))
band ?TINYMT32_UINT32,
temper(#intstate32{
status0 = R0, status1 = _R1,
status2 = R2, status3 = R3,
mat1 = _M1, mat2 = _M2, tmat = TM}) ->
T0 = R3,
T1 = (R0 + (R2 bsr ?TINYMT32_SH8)) band ?TINYMT32_UINT32,
T2 = T0 bxor T1,
T1M = (-(T1 band 1)) band ?TINYMT32_UINT32,
T2 bxor (R#intstate32.tmat band T1M).
T2 bxor (TM band T1M).

%% @doc Generate 32bit-resolution float from the TinyMT internal state.
%% (Note: 0.0 =< result < 1.0)
Expand Down

0 comments on commit dd1f6ee

Please sign in to comment.