diff --git a/.gitignore b/.gitignore index 83a9c718..f1ec3d90 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ numpy.txt _go/ _runtime/ _tinygo/ +_output/ build.dir/ .vscode/ diff --git a/_demo/rand/rand.go b/_demo/rand/rand.go new file mode 100644 index 00000000..106398a9 --- /dev/null +++ b/_demo/rand/rand.go @@ -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) +} diff --git a/c/math/rand/rand.go b/c/math/rand/rand.go new file mode 100644 index 00000000..c61845c7 --- /dev/null +++ b/c/math/rand/rand.go @@ -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()