Logic Building Episode 1 : Generate N digit random number based on input
Problem Statement: Write a function that generates an N digit random number based on the N input. Input: N=5 Output: XXXXX (N digit random number) Input: N= 2 Output: XX Give try yourself, before look at the solution and share your solution in the comment. package main import ( " fmt " " math/rand " " strconv " " strings " " time " ) // random func will generate a random digit number based on param. func random ( param int ) { rand . Seed ( time . Now (). UnixNano ()) chars := [] rune ( "0123456789" ) var b strings . Builder for i := 1 ; i <= param ; i ++ { b . WriteRune ( chars [ rand . Intn ( len ( chars ))]) } str := b . String () i , err := strconv . Atoi ( str ) if err != nil { fmt . Println ( "error while convert" ) } fmt . Println ( i ) } // Driver func main () { random ( 5 ) // N = 5 } Output: λ ra...