Arc4random_uniform unrecognized in Xcode 7 and Swift 2

Xcode 7.1.1 does not autocomplete for arc4random_uniform, instead the following is found:

arc4random_addrandom(UnsafeMutablePointer<UInt8>, Int32)
arc4random_buf(UnsafeMutablePointer<Void>, Int)

Does anyone know why this is happening?

It doesn’t auto-complete but the function still works when typed out completely. However, thats going to be the least of your problems with that section :wink:

First your’e going to have the move to using the for _ in 1…<length to get rid of the unnecessary unused var warning.
Then, you’re going to encounter the change of a String no longer being a collection of characters and hence the .count property no longer being available.

The following explains it more fully, but basically, Unicode allows for potentially two characters in the data to represent one character visually (think e with an acute accent), so it makes problems for index access of strings and we need to access the String.characters property and functions to access the count of characters. … -CH7-ID285

I ended up with the following, hope it helps!

import Foundation

private let chars = “0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”

func generateRandomString(length: Int) -> String {

var string = ""

for _ in 1..<length {
return string


func generateRandomCharacter()-> Character{
let randomIndex = Int(arc4random_uniform(UInt32(chars.characters.count)))
let charPosition = chars.characters.startIndex.advancedBy(randomIndex)
let char = chars[charPosition]
return char

Never mind me - i just found the swift 2 companion notes.

Interesting dive though :stuck_out_tongue: