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
-2
votes
2 answers

Why do I get this error and how can I fix it? Swift

I am making a guess the card game and i get this weird error which I cannot fix when I create a random number for the symbols and the card numbers. This is the error: An image of the error let cardSymbols = ["Spades", "Hearts", "Diamonds",…
-2
votes
1 answer

I have a CGFloat value and I want to add another CGFloat value and display it using random numbers in ios

I want to add two CGFloat numbers and display them using random numbers, but don't know how to do that.. My code is : CGFloat latitude = 31.303702; CGFloat longitude = 75.594905; and the value I want to add to both cgfloat values is CGFloat…
-2
votes
2 answers

Returning first 3 values in a array

I have a array that looks like this: var myArray = ["1one", "1two", "1three", "1four", "1five", "1six"] And to get random, I use this: var originalNames = [String]() func getRandomName() -> String { if (names.count == 0) { names =…
Roduck Nickes
  • 1,021
  • 2
  • 15
  • 41
-2
votes
1 answer

Generate buttons randomly (Swift)

I am making an app where you click a button, causing a new button to appear, and the button you clicked to disappears. I want the buttons to appear randomly, and I also want it to always be 4 buttons visible all the time. I can't really figure out…
Marius Hegg
  • 99
  • 10
-2
votes
2 answers

Is there a way to set restrictions on arc4random()'s results?

I'm making three random choices between two classes, A and B. I need to avoid getting B all three times. Is there a way to stop arc4random() from giving me that result?
DwemerTech
  • 11
  • 3
-2
votes
1 answer

Why arc4random_uniform can be set as a constant?

Why arc4random_uniform can be set as a constant? I noticed that in multiple examples. arc4random_uniform generates a new value every time it is called and I thought value of a constant should never change? It looks much more like a variable.
-2
votes
1 answer

Is there a way to shorten if-statements?

I am wondering if there is a way to the following code shorter. I have done this same type of thing for other Xcode projects in the past and it has been very time consuming. Here is the code: @IBAction func flashButton(sender: UIButton) { …
Bigfoot11
  • 911
  • 2
  • 11
  • 25
-2
votes
2 answers

Swift arc4random_uniform unWorking

I made a variable using arc4random this way: var a = Int(arc4random_uniform(25)) I want a to be between 0 and 24. Sometimes it works fine, but sometimes it gives a HUGE value with about 20 characters! What causes this and how can I fix it?
Liad
  • 21
  • 1
-2
votes
2 answers

Objective C: Do I have to import arc4random ( )?

I'm trying to generate a random number between 0 and 3 by saying int i = arc4Random() % 3; but it keeps giving me the warning "implicit declaration of function 'arc4Random' is invalid in c99
Aeisys
  • 367
  • 1
  • 3
  • 13
-2
votes
2 answers

using arc4random does not place images as "random" as I would like

I would like the images to appear more randomly than they do with this code: //placing images on the screen -(void)PlaceImage { RandomImagePosition = arc4random() %1000; Image.center = CGPointMake(570, RandomImagePosition); // the…
dev_help
  • 119
  • 10
-2
votes
1 answer

How to randomly spawn ccsprites one at a time with a delay in between

Hello I am making a cocos2d side scroller app and I want enemies to fly at the character at random. I am a beginner to objective c and cocos2d so this may seem like a simple question but any help is valuable. Would arc4random help?? Here is my code…
PoKoBros
  • 701
  • 3
  • 9
  • 25
-2
votes
3 answers

How to randomise words

Im trying to display a word picked at random on an action from my array Ive looked at Randomize words but still not getting it to work. My label text is _answer in my viewDidLoad: NSArray *words = [NSArray arrayWithObjects: @"Blue", @"Green",…
JSA986
  • 5,870
  • 9
  • 45
  • 91
-3
votes
1 answer

Make arc4random, more random?

I am trying to make random questions appear in my quiz. Right now I am using arc4random() to pull a random number for a switch statement and that's what's displayed on buttons and the labels but it likes to duplicate the questions quite a bit. How…
Schmob
  • 9
  • 3
-3
votes
2 answers

Maximum return value of arc4random()

For some reason I'm not able to find any sort of official doc telling me what the range is for arc4random(). I've seen in some non-authoritative sources that it's 2^32 - 1, a little over 4 billion. Can anyone confirm this? If so, can you link to an…
Bill L
  • 2,576
  • 4
  • 28
  • 55
-3
votes
1 answer

Random Number Generation between user input variables in Swift

How can I create a random number between two random numbers that come from user input variables in swift using arc4random().
1 2 3
20
21