Skip to content

Commit

Permalink
remove linkname for version >= 1.22
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyunhao116 committed May 30, 2024
1 parent cda9205 commit 5076ca6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# fastrand

> As of Go1.22, the fastrand is just a wrapper of `math/rand/v2`, please use the standard library instead.
>
> The fastrand is developed from the background that `math/rand` is unscalable. Because `math/rand` and `math/rand/v2` become scalable since Go1.22, there is no need to use this library.
`fastrand` is the fastest pseudo-random number generator in Go. Support most common APIs of `math/rand`.

This generator base on the Go runtime per-M structure, and the init-seed provided by the Go runtime, which means you can't add your seed, but these methods scale very well on multiple cores.
Expand Down
17 changes: 10 additions & 7 deletions runtime_go122.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
package fastrand

import (
_ "unsafe"
"math/rand/v2"
)

//go:linkname runtimefastrand runtime.cheaprand
func runtimefastrand() uint32
func runtimefastrand() uint32 {
return rand.Uint32()
}

//go:linkname runtimefastrand64 runtime.cheaprand64
func runtimefastrand64() uint64
func runtimefastrand64() uint64 {
return rand.Uint64()
}

//go:linkname runtimefastrandu runtime.cheaprandu
func runtimefastrandu() uint
func runtimefastrandu() uint {
return uint(rand.Uint64())
}

0 comments on commit 5076ca6

Please sign in to comment.