Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to generate a random number between 1 and 9 in Go

1 Answer

0 votes
package main

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

func main() {
    rand.Seed(time.Now().UnixNano())
    
    for i := 0; i < 25; i++ {
        digit := rand.Intn(9 + 1 - 1) + 1 // generates a random digit between 1 and 9
        //digit := rand.IntN(max + 1 - min) + min
        fmt.Println(digit)
    }
}


/*
run:

3
9
6
4
1
1
8
3
4
3
3
8
1
1
7
2
7
3
5
4
4
3
3
1
5

*/

 



answered Nov 10, 2024 by avibootz

Related questions

1 answer 86 views
1 answer 92 views
1 answer 98 views
1 answer 114 views
1 answer 172 views
...