Sobes.tech
Junior — Senior

Get a set of n unique random numbers

livecode

Task condition

It is necessary to write a function uniqRandn(n int) []int that returns an array of exactly n distinct random integers. Each time the program is run, the set of numbers should be random, but there should be no duplicates within the result.

import (
 "fmt"
 "math/rand"
)

func main() {
 fmt.Println(uniqRandn(10))
}

func uniqRandn(n int) []int {
 // ...
}

The function should work correctly for any values of n (within reasonable limits), guaranteeing the uniqueness of all elements in the returned slice.