Skip to content

Commit

Permalink
add math/rand (#403)
Browse files Browse the repository at this point in the history
c/math/rand
  • Loading branch information
tsingbx authored Jun 24, 2024
1 parent 32a66be commit ec1b1ff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ numpy.txt
_go/
_runtime/
_tinygo/
_output/
build.dir/
.vscode/

Expand Down
15 changes: 15 additions & 0 deletions _demo/rand/rand.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/math/rand"
)

func main() {
var s c.Uint = 6
rand.Srand(s)
rr := rand.RandR(&s)
r := rand.Rand()
println("r:", r)
println("rr:", rr)
}
23 changes: 23 additions & 0 deletions c/math/rand/rand.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package rand

import (
_ "unsafe"

"github.com/goplus/llgo/c"
)

const (
LLGoPackage = "decl"
)

//go:linkname Rand C.rand
func Rand() c.Int

//go:linkname RandR C.rand_r
func RandR(*c.Uint) c.Int

//go:linkname Srand C.srand
func Srand(c.Uint)

//go:linkname Sranddev C.sranddev
func Sranddev()

0 comments on commit ec1b1ff

Please sign in to comment.