Linked Questions

5 votes
2 answers
12k views

tl:dr; How do I generate a random number, because the method in the book picks the same numbers every time. This seems to be the way in Swift to generate a random number, based on the book released ...
slooker's user avatar
  • 151
5 votes
1 answer
4k views

I'm able to pick a random number for my items in my game but is it possible to pick a random number between 2 numbers? so instead of let number = (arc4random_uniform(100)) I would like something ...
Kristof.V's user avatar
  • 143
0 votes
2 answers
879 views

How do I generate a random number in Swift language that can be used in math, such as addition. Basically I just want to be able to generate a random number and then add it to a count that I have. For ...
Bennnn's user avatar
  • 17
0 votes
1 answer
827 views

I was wondering if this is the best way to generate a random number in Swift. This is what I have thought of thus far: var randomNumber:Int = random() * 100 + 1 //What value does this return? I was ...
Linuxn00b's user avatar
  • 151
0 votes
1 answer
539 views

I'm having trouble trying to find a way to return a random number between 1 and 9,000,000,000,000,000 I have made a randomNumberBetween function using UInt32 but I just havn't been able to do the ...
Troy R's user avatar
  • 426
0 votes
1 answer
429 views

How sort the documents in a collection randomly. This is the function I use to get the documents, how can I sort them randomly? func fetchExplore() { let query = COLLECTION_POSTS.limit(to: 6) ...
Santiago Padilla's user avatar
0 votes
1 answer
297 views

I have to text fields on a differnet scene.One text field has a smaller number and another one has a bigger number.I need to take those numbers and generate a random number using the smallest number ...
j4awesome's user avatar
-5 votes
1 answer
79 views

What am I doing wrong? It won't let me use random. PickRandom() func PickRandom() { let RandomNumber = random() % QuizObject.count // error here Btn1.setTitle(QuizObject[RandomNumber]....
Damilola Adedeji's user avatar
344 votes
10 answers
79k views

Why exactly is there "modulo bias" when using a random number generator, like rand() in C++?
user1413793's user avatar
  • 9,427
44 votes
3 answers
19k views

I'm needing to create a random bool value in my game, in Swift. It's basically, if Yes (or 1), spawn one object, if No (or 0), spawn the other. So far, looking at this question and a similar one on ...
Reanimation's user avatar
  • 3,356
55 votes
1 answer
51k views

I've seen old posts about the differences between random and arc4random in Objective-C, and I've seen answers to this online but I didn't really understand, so I was hoping someone here could explain ...
Brennan Adler's user avatar
28 votes
7 answers
8k views

I've written a simple Bag class. A Bag is filled with a fixed ratio of Temperature enums. It allows you to grab one at random and automatically refills itself when empty. It looks like this: class ...
Shaun Inman's user avatar
  • 1,968
14 votes
5 answers
20k views

I'm pretty new to Swift and programming logic in general so bear with me How can you generate a random number between 0 and 9 in Swift without repeating the last generated number? As in the same ...
bmaliel's user avatar
  • 353
14 votes
4 answers
5k views

I'm working with Swift in Ubuntu, and I am getting an error that arc4random is an unresolved identifier. More information on this known bug here. Basically, the function only exists in BSD distros. I'...
Tyress's user avatar
  • 3,653
12 votes
1 answer
2k views

According to this documentation, arc4random_uniform() is recommended over constructions like arc4random() % upper_bound as it avoids "modulo bias" when the upper bound is not a power of two. How bad ...
AJ222's user avatar
  • 1,134

15 30 50 per page