# Ch15: P416 - Int.random?

**URL:** <https://forums.kodeco.com/t/ch15-p416-int-random/29131>\
**Category:** 2D iOS & tvOS Games by Tutorials\
**Created:** [May 1, 2017, 6:40pm UTC](https://forums.kodeco.com/t/ch15-p416-int-random/29131 "2017-05-01T18:40:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbourne](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/dbourne/32/81494_2.png) [@dbourne](https://forums.kodeco.com/u/dbourne)\
**Post date:** [May 1, 2017, 6:40pm UTC](https://forums.kodeco.com/t/ch15-p416-int-random/29131/1 "2017-05-01T18:40:37Z")

</div>

Int doesn’t seem to have the method random. It seems to be used in SKTUtilies as well.

I used

```
    let intRandom = 1 + Int(arc4random_uniform(100))

```

// if Int.random(min: 1, max: 100) \<= platformPercentage  
if intRandom \<= platformPercentage

Am I missing something?

---

<div class="post-metadata">

**Author:** ![narrativium](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/narrativium/32/110937_2.png) [@narrativium](https://forums.kodeco.com/u/narrativium)\
**Post date:** [May 2, 2017, 9:24am UTC](https://forums.kodeco.com/t/ch15-p416-int-random/29131/2 "2017-05-02T09:24:12Z")

</div>

The random function is in SKTUtilities because it’s a useful function for things like random generation of game levels, but not an essential function of integers - so it’s not in core Swift, or even in the Foundation module.

`arc4random` and its variants are in Swift, but they’re usually overkill for the kinds of simple number generation used in this game example - I believe they’re intended for things like encryption algorithms.

I believe there have been discussions in the Swift Evolution mailing lists about adding a ‘simple’ random number generator to Int types at a more ‘core’ level, but I don’t know if those have progressed into proposals which might be acted upon.

… I’m not sure if that answered the question you were asking. Did that help?

---

<div class="post-metadata">

**Author:** ![dbourne](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/dbourne/32/81494_2.png) [@dbourne](https://forums.kodeco.com/u/dbourne)\
**Post date:** [May 2, 2017, 3:05pm UTC](https://forums.kodeco.com/t/ch15-p416-int-random/29131/3 "2017-05-02T15:05:30Z")

</div>

Thanks for the reply. After a little move searching…I found

Interesting. I had the SKTUtils folder inside the inner DropCharge folder. I gather GameScene.swift couldn’t access it globally from there. I moved the folder inside the outer DropCharge folder and it picked it up OK. No error.

BTW, the Int.random functions all use arc4random\_uniform 😉

On a different issue the location of ’ physicsWorld.contactDelegate = self’ in didMove(to seems to be ‘important’. I had it at the top of the function and the ‘marine’ didn’t come down from above the screen, although I may not have waited long enough. When I put that line at the end of function it worked. I may not have checked this properly as I was expecting a quicker drop for the player.

---

<div class="post-metadata">

**Author:** ![dbourne](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/dbourne/32/81494_2.png) [@dbourne](https://forums.kodeco.com/u/dbourne)\
**Post date:** [May 2, 2017, 3:18pm UTC](https://forums.kodeco.com/t/ch15-p416-int-random/29131/4 "2017-05-02T15:18:45Z")

</div>

No, that didn’t seem to help after all. I checked on page 219 and I don’t see any ‘special’ code to make SKTUtils visible to the rest of program. I tried deleting the folder and copying it directly into the outer DropCharge folder. Clean and still a problem with Int.random.
