Questions tagged [arc4random]

The arc4random() function returns pseudo-random numbers in the range of 0 to (2*32)-1

The arc4random() function uses the key stream generator employed by the arc4 cipher, which uses 8*8 8 bit S-Boxes. The S-Boxes can be in about (2*1700) states. The arc4random() function returns pseudo-random numbers in the range of 0 to (2*32)-1, and therefore has twice the range of rand() and random().

For example, a drop-in replacement for the traditional rand() and random() functions using arc4random():

#define foo4random() (arc4random() % ((unsigned)RAND_MAX + 1))
305 questions
0
votes
1 answer

How do I prevent unfilled UITextFields from showing up on a randomized count? Xcode

I am working on an app in which there are five UITextFields in one view controller, the user can fill the text fields they want and when they press a UIButton they'll get a randomized answer on a second view controller via a UILabel. I got it to…
esierr1
  • 117
  • 3
  • 12
0
votes
1 answer

Random numbers no repeat loop generator on xcode

I know it's newbie question but I really need some help. I am trying to create a while loop with an integer temporary array on Xcode for four numbers. On every loop I want to check the previous number and store it to my table until that fills the…
user2437643
  • 1
  • 1
  • 1
0
votes
2 answers

Randomly scan through every coordinate

TL;DR Randomly access every tile in a tilemap I have a way of generating random positions of tiles by just filling an entire layer of them (its only 10x10) then running a forloop like for (int x = 0; x < 13; x++) { for (int y =…
Oscar Apeland
  • 6,422
  • 7
  • 44
  • 92
0
votes
1 answer

arc4random always returns same initial value on app start

I am developing an application for the iphone that, in viewDidLoad, calls arc4random to get a random number. My problem is that each time the application starts, it gets the same number from arc4random. I ought to point out that I see this…
0
votes
2 answers

Which one is the correct way of using "arc4rand()"

I am new to objective C and trying to understand arc4random(). There are so many conflicting explanations on the web. Please clear my confusion, which of the following is correct: // 1. arc4random() % (toNumber - fromNumber) +…
0
votes
1 answer

randomly distribute sprites

I have defined: #define kNumAstroids 15 and Sprite Add _robbers = [[CCArray alloc] initWithCapacity:kNumAstroids]; for (int i = 0; i < kNumAstroids; ++i) { CCSprite *asteroid = [CCSprite spriteWithSpriteFrameName:@"robber.png"]; …
Jems Leo
  • 39
  • 4
0
votes
3 answers

How to store Array values in dictionay in iphone application

I am getting trouble in one of my app . I have 36 images & 36 sound and 36 text this all name are same now i want to Declare array of this all means array of images array of text and array of sound and now randomly want to display 9 images from…
0
votes
1 answer

Using a counter in same method as arc4random causes button to remain stationary. (iOS)

I have a button that I'd like to randomly display on the screen each time it is pressed. I'm using arc4random to make this happen. But once I incorporate a counter into this method, the random portion stops working. Any ideas why this is happening…
Dave123
  • 306
  • 2
  • 4
  • 13
0
votes
1 answer

Cocos2d Random object from array not being called

I have created an array which stores either red, yellow, or green (3, 2, or 1) based on what the user hits. I want the code to choose a random number in the array and display the corresponding color on the screen. However, when the code runs, the…
chandhooguy
  • 452
  • 3
  • 14
0
votes
3 answers

Generate two random numbers on the same line of code?

I've stumbled into a quite surprising problem while doing some iOS stuff with random numbers. Compare these: a) int xOffsetSign = randomIntWithUpperLimit(2) ? 1:-1; int yOffsetSign = randomIntWithUpperLimit(2) ? 1:-1; int xOffset =…
Ricardo Sanchez-Saez
  • 9,466
  • 8
  • 53
  • 92
0
votes
1 answer

iOS - Unknown Bug In Random Number Generation?

I'm trying to put some objects in the screen at random positions. I use arc4random() to generate a new random number. But it seems that the function is not working properly, here's the code and traced result: Code : UIView *stateView = [[UIView…
Sepehrom
  • 1,335
  • 2
  • 16
  • 33
0
votes
1 answer

Random generator using arc4random in jailbreak app

i'm developing an app with Theos and i want to add a random image generator. i have an nsarray of image and i don't know how to use arc4random (). can you help me showing some sample code? (:
0
votes
2 answers

Setting a range of coordinates with arc4random iOS

I need to randomly place a UIButton around the iPhone screen when a button is pressed. I can do this successfully, but my UIButton appears cut off on the edges sometimes. So my question is, how can I set a range of coordinates for arc4random to work…
Aaron Chapman
  • 44
  • 1
  • 9
0
votes
1 answer

How to distribute cards until the entire card stack/pack is distributed based on shuffling/random numbers, with a click of a button?

I am creating my first card game, and need to shuffle the cards. So for starters, I have created a shuffle button for a sample stack of 4 values with the line: int i = arc4random() % 4; NSLog(@"%d", i); Shuffling works well, but I want this button…
Glyphs
  • 97
  • 1
  • 1
  • 7
0
votes
1 answer

Random images error

I'm making an app that when you press a button it give you a random image. When I run it I don't get any error, but when I click on the button the app freeze and on xcode it says "Thread 1: breakpoint 1.1" at the end of this code right…
emiliomarin
  • 362
  • 3
  • 22