Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
Last active June 4, 2024 17:39
Show Gist options
  • Save TheMuellenator/9fdb0d41d6343218ca1bcb6fb724949e to your computer and use it in GitHub Desktop.
Save TheMuellenator/9fdb0d41d6343218ca1bcb6fb724949e to your computer and use it in GitHub Desktop.
iOS repl.it - Randomisation Challenge Solution
let alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
//The number of letters in alphabet equals 26
var password = alphabet[Int.random(in: 0...25)] + alphabet[Int.random(in: 0...25)] + alphabet[Int.random(in: 0...25)] + alphabet[Int.random(in: 0...25)] + alphabet[Int.random(in: 0...25)] + alphabet[Int.random(in: 0...25)]
print(password)
@h40hm4ru
Copy link

h40hm4ru commented May 7, 2024

let alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

var password = ""
for _ in 1 ... 6 {
    password += alphabet.randomElement()!
}

print(password)

@ParsaMotiallah
Copy link

let alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

let randomElements = Array(alphabet.shuffled().prefix(6))

let password = randomElements.joined()
print (password)

@toporusan
Copy link

let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
var password = ""
while password.count != 6 {
password = password + alphabet[Int.random(in: 0 ... alphabet.count - 1)]
}
print(password)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment