Golang crypto/rand.Prime() function example
package crypto/rand
Prime returns a number, p, of the given size, such that p is prime with high probability. Prime will return error for any error returned by rand.Read(1st parameter) or if bits(2nd param) < 2.
Golang crypto/rand.Prime() function usage example
package main
import (
"crypto/rand"
"fmt"
"math/big"
)
func main() {
var p *big.Int
var bits int
var err error
bits = 99
p, err = rand.Prime(rand.Reader, bits)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%d\n", p)
}
Sample output :
go run cryptorandprime.go
565350588010525112928194028091
Reference :
Advertisement
Something interesting
Tutorials
+11.7k Golang : How to detect a server/machine network interface capabilities?
+41.2k Golang : How to count duplicate items in slice/array?
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+8.9k Golang : Accept any number of function arguments with three dots(...)
+4.7k Golang : How to pass data between controllers with JSON Web Token
+46.2k Golang : Read tab delimited file with encoding/csv package
+12.7k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+13k Golang : Calculate elapsed years or months since a date
+4.8k MariaDB/MySQL : Form select statement or search query with Chinese characters
+9.4k Golang : Apply Histogram Equalization to color images
+15k Golang : How do I get the local IP (non-loopback) address ?
+23.9k Golang : Fix type interface{} has no field or no methods and type assertions example