Good day trying to figure out how to work with a swift in a playground, you need a function, structure or extension to generate random numbers. Found just such a structure

struct Math { private static var seeded = false static func randomFractional() -> CGFloat { if !Math.seeded { let time = Int(NSDate().timeIntervalSinceReferenceDate) srand48(time) Math.seeded = true } return CGFloat(drand48()) } } Math.randomFractional() 

I also need for example, I in xcode the appearance of different objects in different places

  • what arc4random_uniform () doesn't like? - Max Mikheyenko

1 answer 1

Use standard arc4random() or arc4random_uniform() . Any variations with randomizing numbers with these functions are feasible.

  • well, that's enough, my comments will be enough to give for my answers - Max Mikheyenko
  • Sorry, did not notice. - Otlichnick
  • they didn't notice three times :) - Max Mikheyenko