mirror of
https://github.com/jimeh/rands.git
synced 2026-02-19 03:16:39 +00:00
randsmust is specifically intended as an alternative to rands for use in tests. All functions return a single value, and panic in the event of an error. This makes them easy to use when building structs in test cases that need random data. Internally the package simply calls the equivalent function from the rands package, and panics if a error is returned.
24 lines
371 B
Go
24 lines
371 B
Go
package randsmust
|
|
|
|
import "github.com/jimeh/rands"
|
|
|
|
// Int generates a random int ranging between 0 and max.
|
|
func Int(max int) int {
|
|
r, err := rands.Int(max)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return r
|
|
}
|
|
|
|
// Int64 generates a random int64 ranging between 0 and max.
|
|
func Int64(max int64) int64 {
|
|
r, err := rands.Int64(max)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return r
|
|
}
|