Answers for "golang generate random numeric string"

Go
2

random number golang

// Uniform Random int (min <= x <= max)
x = rand.Intn(max - min) + min

// Uniform random float (0 <= x <= 1)
x = rand.Float64()  

// Uniform random float (min <= x <= max)
x = (rand.Float64() * (max - min)) + min
Posted by: Guest on March-23-2020
0

golang generate random string

package main

import (
    "fmt"
    "time"
    "math/rand"
)

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func randSeq(n int) string {
    b := make([]rune, n)
    for i := range b {
        b[i] = letters[rand.Intn(len(letters))]
    }
    return string(b)
}

func main() {
    rand.Seed(time.Now().UnixNano())

    fmt.Println(randSeq(10))
}
Posted by: Guest on January-04-2022

Code answers related to "golang generate random numeric string"

Browse Popular Code Answers by Language