---
title: "Generating Random Numbers in Objective-C"  
description: "Generating Random Numbers in Objective-C"  
author: "Anonymous User"  
published: 2015-08-17  
updated: 2015-08-18  
canonical: https://www.mindstick.com/forum/33419/generating-random-numbers-in-objective-c  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Generating Random Numbers in Objective-C

I'm a [Java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) head mainly, and I want a way to generate a pseudo-[random](https://www.mindstick.com/interview/34417/how-to-use-random-numbers-in-numpy) number between 0 and 74. In Java I would use the [method](https://www.mindstick.com/forum/166/webservice-method):

Random.nextInt(74)

I'm not interested in a [discussion](https://answers.mindstick.com/qa/44930/what-is-the-procedure-for-half-an-hour-discussion) about seeds or [true](https://yourviews.mindstick.com/view/81326/boycott-chinese-products-dream-will-come-true) randomness, just how you accomplish the same [task](https://www.mindstick.com/forum/161761/what-is-the-difference-between-task-and-thread) in Objective-C. I've scoured The [Google](https://www.mindstick.com/articles/43833/google-lighthouse-and-how-is-it-changing-the-way-we-development-and-design-websites), and it just seems to be lots of different and conflicting bits of information.

## Replies

### Reply by Anonymous User

Use the arc4random_uniform(upper_bound) function to generate a random number within a range. The following will generate a number between 0 and 73 inclusive.

**arc4random_uniform(74)**

arc4random_uniform(upper_bound) avoids modulo bias

arc4random_uniform() will return a uniformly distributed random number less than upper_bound. 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.


---

Original Source: https://www.mindstick.com/forum/33419/generating-random-numbers-in-objective-c

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
