Member-only story
5 Swift Extensions to Generate Randoms
Using Swift extensions to generate random numbers, characters and, more

Two principal industries use random numbers regularly. The games industry and the cryptographic one. So I thought it might make an interesting article to put together a collection of random number routines —
Now, I spare you the code to generate a random number, because you surely already know that, let us jump in with well — with more. Most of the extensions presented are cryptographically safe, with the caveat noted on Apple’s man page — a caveat that says — cryptographic quality may vary across platforms.
A Random Character
Looking beyond Int, Double, and Bool randoms then I want a random Character, here is an extension to do that:
A Random String
As you well know Characters are not strings in swift, so here is a routine to return a random string [one or more characters, yes it is confusing].
A Self Sourced Random String
Now, maybe you want to supply your own string of characters and get a random selection back. Here are a couple of extensions to do just that. The first takes an array of strings. The second takes a single string.
Here is another take on the same thing — done differently. As you can see this takes an array of strings.