vendredi 30 septembre 2016

Repeatable random number sequence in swift [duplicate]

This question already has an answer here:

Is it possible to create a repeatable random number sequence in swift?

Something like srand() and rand():

import Foundation

// With srand we start a sequence of random numbers.
// ... Each rand call returns a value in a predictable sequence.
print("Test")
srand(5)
for i in 0...3
{
    print(rand())
}

// Demonstrate the repeat sequence.
print("Test again")
srand(5)
for i in 0...3
{
    print(rand())
}

Which would output something like:

Test

84035

1412376245

1670799424

629750996

Test again

84035

1412376245

1670799424

629750996

Seems like only arc4random() is available and it does not appear to be repeatable.




Aucun commentaire:

Enregistrer un commentaire