| 
									
										
										
										
											2018-11-13 17:43:25 +03:00
										 |  |  | // For more tutorials: https://blog.learngoprogramming.com | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // Copyright © 2018 Inanc Gumus | 
					
						
							|  |  |  | // Learn Go Programming Course | 
					
						
							|  |  |  | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/ | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2018-12-18 15:20:37 +03:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2018-11-13 17:43:25 +03:00
										 |  |  | 	"math/rand" | 
					
						
							|  |  |  | 	"time" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func main() { | 
					
						
							|  |  |  | 	rand.Seed(time.Now().UnixNano()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-18 15:20:37 +03:00
										 |  |  | 	const max = 5 | 
					
						
							| 
									
										
										
										
											2018-11-13 17:43:25 +03:00
										 |  |  | 	var uniques [max]int | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-18 15:20:37 +03:00
										 |  |  | 	// It's harder to make a program dynamic using arrays | 
					
						
							|  |  |  | 	// max, _ := strconv.Atoi(os.Args[1]) | 
					
						
							|  |  |  | 	// var uniques [10]int | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-13 17:43:25 +03:00
										 |  |  | loop: | 
					
						
							|  |  |  | 	for found := 0; found < max; { | 
					
						
							| 
									
										
										
										
											2018-12-18 15:20:37 +03:00
										 |  |  | 		n := rand.Intn(max) + 1 | 
					
						
							|  |  |  | 		fmt.Print(n, " ") | 
					
						
							| 
									
										
										
										
											2018-11-13 17:43:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		for _, u := range uniques { | 
					
						
							|  |  |  | 			if u == n { | 
					
						
							|  |  |  | 				continue loop | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		uniques[found] = n | 
					
						
							|  |  |  | 		found++ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-18 15:20:37 +03:00
										 |  |  | 	fmt.Println("\n\nuniques:", uniques) | 
					
						
							| 
									
										
										
										
											2018-11-13 17:43:25 +03:00
										 |  |  | } |