Skip to content

Commit

Permalink
RAND_MAX (gotranspile#15)
Browse files Browse the repository at this point in the history
Add RAND_MAX to sdlib.

Solves gotranspile#14
  • Loading branch information
TotallyGamerJet committed Jul 15, 2021
1 parent b05e342 commit ac40214
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion libs/stdlib.go
Expand Up @@ -2,7 +2,8 @@ package libs

import (
"os"

"fmt"

"github.com/gotranspile/cxgo/runtime/cmath"
"github.com/gotranspile/cxgo/runtime/libc"
"github.com/gotranspile/cxgo/types"
Expand Down Expand Up @@ -133,6 +134,7 @@ size_t wcstombs(char *restrict, const wchar_t *restrict, size_t);
int wctomb(char *, wchar_t);
`,
}
l.Header += fmt.Sprintf("#define RAND_MAX %d\n", libc.RandMax)
l.Declare(
c.NewIdent("getenv", "os.Getenv", os.Getenv, c.FuncTT(c.Go().String(), c.Go().String())),
)
Expand Down
9 changes: 7 additions & 2 deletions runtime/libc/rand.go
@@ -1,9 +1,14 @@
package libc

import "math/rand"
import (
"math"
"math/rand"
)

const RandMax = math.MaxInt32

func Rand() int32 {
return int32(rand.Int())
return int32(rand.Intn(RandMax))
}

func SeedRand(seed uint32) {
Expand Down

0 comments on commit ac40214

Please sign in to comment.