Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func getRamdom(_ from: Int, toN: Int, _ k:Int)-> [Int]{
- var res = [Int]()
- var to = toN
- var map = [Int: Int]()
- while res.count < k{
- let next = Int.random(in: from ... to)
- if let number = map[next]{
- res.append(number)
- }else{
- res.append(next)
- }
- map[next] = to
- to -= 1
- }
- return res
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement