user8350399
user8350399

Reputation:

Best way to determine when to call a function randomly

I currently determine when to do a task randomly within the update(_ currentTime: TimeInterval) function by generating two numbers randomly and doing the task if they are equal. When I do this I call a function I created to generate the random numbers twice, which I think may be an overload after a while.

Does anyone else have an easier or more efficient way to do this?

I am using Swift within Xcode.

Upvotes: 0

Views: 44

Answers (1)

rmaddy
rmaddy

Reputation: 318884

Just call the random number generator once and see if it equals 0 ( or any other specific number in the random range). There is no reason to compare two random numbers for equality.

Upvotes: 1

Related Questions