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
+10.1k Golang : Print how to use flag for your application example
+47.8k Golang : Convert int to byte array([]byte)
+25.3k Golang : Convert uint value to string type
+16k Golang : Read large file with bufio.Scanner cause token too long error
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+12.9k Python : Convert IPv6 address to decimal and back to IPv6
+14.1k Golang : Check if a file exist or not
+7.2k Golang : Dealing with postal or zip code example
+20.5k Golang : Pipe output from one os.Exec(shell command) to another command
+9k Golang : How to use Gorilla webtoolkit context package properly
+7.9k Golang : How to feed or take banana with Gorilla Web Toolkit Session package