Press ESC to close

Swift Random Number Generation

It is very important to generate random numbers in our mobile applications or in any application. If you want to leave a job to chance in the software, you have to do it by generating a random number. There’s more than one way to do this. If you want, you can take the clock and print it on the screen. In this article I will describe the functions available in Swift. We can create a random number on this number more simply.

To create a random number, we need to use the Arc4Random function. To briefly mention this function; With this function, you can generate infinite digit numbers. Sometimes this function works, but you may want to generate random numbers within certain intervals. To generate an infinite number of digits, you can add the following code prosumatically.

let uretilen = arc4random()

But, as I mentioned above, you may want to generate a random number in a limited area. For this we need to use another function. We need to set the upper limit. With the function below you can also provide a solution.

let uretilen = arc4random_uniform(50)

Thus, we can easily generate random numbers. If you have any questions, please contact me by email or comment.

Leave a Reply

Your email address will not be published. Required fields are marked *