mardi 18 juin 2019

Error with Random number generation in Swift on Linux?

I have a piece of code as follows:

extension Array {
  fileprivate func random() -> Element {
    let idx: Int
    #if os(Linux)
    idx = Int(random() % count)
    #else
    idx = Int(arc4random_uniform(UInt32(count)))
    #endif

    return self[idx - 1]
  }
}

When I attempt to deploy my app it errors when running docker using linux, the issue as follows:

error: binary operator '%' cannot be applied to operands of type 'Int32' and 'Int' idx = Int(rand() % count)

I tracked the issue down to this funciton but cant work out the fix here as it already is meant to provide an alternative handling for Linux...




Aucun commentaire:

Enregistrer un commentaire