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
+9.2k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+8.3k Golang : Auto-generate reply email with text/template package
+8.2k Golang : Metaprogramming example of wrapping a function
+5.7k Get website traffic ranking with Similar Web or Alexa
+28.6k Get file path of temporary file in Go
+15.3k Golang : Get all local users and print out their home directory, description and group id
+20.6k Nginx + FastCGI + Go Setup.
+6.6k Golang : Embedded or data bundling example
+48.5k Golang : Upload file from web browser to server
+13.6k Golang : Qt progress dialog example
+8.9k Golang : Sort lines of text example