add math/rand (#403)

c/math/rand
This commit is contained in:
tsingbx
2024-06-24 15:53:26 +08:00
committed by GitHub
parent 32a66be555
commit ec1b1ffe16
3 changed files with 39 additions and 0 deletions

1
.gitignore vendored
View File

@@ -19,6 +19,7 @@ numpy.txt
_go/
_runtime/
_tinygo/
_output/
build.dir/
.vscode/

15
_demo/rand/rand.go Normal file
View File

@@ -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
c/math/rand/rand.go Normal file
View File

@@ -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()