-2
var Password1 : Array = [Int]()
var Password2 : Array = [Int]()

while Password1.count < 800 {

    var RandomNum1 = Int(arc4random_uniform(256))
    var RandomNum2 = Int(arc4random_uniform(256))

    Password1[Password1.count] = RandomNum1
    Password2[Password2.count] = RandomNum2

}

In the line of Password1[Password1.count] = RandomNum1 this appears -> EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

vacawama
  • 150,663
  • 30
  • 266
  • 294

2 Answers2

2

Your Password1 and Password2 arrays are empty. Therefore, you can't index into them without getting an error. Use append to create your arrays:

Password1.append(RandomNum1)
Password2.append(RandomNum2)

Also, variable names should start with a lowercase letter.


If you want to be able to index into the arrays, initialize them with zeroes first:

var password1 = [Int](count: 800, repeatedValue: 0)
var password2 = [Int](count: 800, repeatedValue: 0)

for i in 0..<800 {
    var randomNum1 = Int(arc4random_uniform(256))
    var randomNum2 = Int(arc4random_uniform(256))

    password1[i] = randomNum1
    password2[i] = randomNum2
}
vacawama
  • 150,663
  • 30
  • 266
  • 294
0

You are trying to replace value in keys that does not exists. It's PHP way, not Swift.

Because you already init arrays, you need call append on them to add element at the end of array.

Maks
  • 766
  • 8
  • 11