Skip to content

Commit

Permalink
One extra PRNG iteration (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtereshkov committed Sep 28, 2024
1 parent 8a1610f commit e09c5ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion playground/umka.js

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions runtime/std.um
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,6 @@ const randMax* = 0x7FFFFFFF

randSeed := uint(1)

fn srand*(seed: int) {
if seed > 0 {
randSeed = seed
}
}

fn rand*(): int {
// xorshift
randSeed ~= randSeed << 13
Expand All @@ -342,6 +336,13 @@ fn frand*(): real {
return real(rand()) / randMax
}

fn srand*(seed: int) {
if seed > 0 {
randSeed = seed
rand()
}
}

// Time

type DateTime* = struct {
Expand Down
13 changes: 7 additions & 6 deletions src/umka_runtime_src.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,6 @@ static const char *runtimeModuleSources[] = {
"\n"
"randSeed := uint(1)\n"
"\n"
"fn srand*(seed: int) {\n"
" if seed > 0 {\n"
" randSeed = seed\n"
" }\n"
"}\n"
"\n"
"fn rand*(): int {\n"
" // xorshift\n"
" randSeed ~= randSeed << 13\n"
Expand All @@ -353,6 +347,13 @@ static const char *runtimeModuleSources[] = {
" return real(rand()) / randMax\n"
"}\n"
"\n"
"fn srand*(seed: int) {\n"
" if seed > 0 {\n"
" randSeed = seed\n"
" rand()\n"
" }\n"
"}\n"
"\n"
"// Time\n"
"\n"
"type DateTime* = struct {\n"
Expand Down

0 comments on commit e09c5ef

Please sign in to comment.