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

using arc4random to generate random number to add to string for UI testing login xcode UI testing

I am testing sign up on an app, using xcode UI testing i am wondering how to use the arc4random to generate a random number which will be typed into the app? here is my code but getting a type cannont convert value of type UInt32 to expected…
Billy Boyo
  • 819
  • 2
  • 12
  • 22
-1
votes
1 answer

Initialising a set of dice - using dropValuesWithCount on a GKARC4RandomSource

I'm initialising a set of dice in swift 2.0. I've declared a class Die with a name (:String), a list of states(:[String]) and a face (an index to the states array) (:[Int]) As per the recommendations in the GameplayKit Framework Reference and in…
Paul A.
  • 11
  • 5
-1
votes
1 answer

How to create Random number with special format in Xcode 7 and Swift 2

I have a problem with coding. I am trying to generate a Random number of 8 digits eg: 12345676 that show the number like this 12 34 56 76. A number of two digits, so a blank space, a number of two digits and other blank space... THANKS, The code…
-1
votes
2 answers

swift: how to remove randomly from 1 to 3 items?

My code remove randomly only one coin. How i can remove randomly from 1 to 3 coins? @IBAction func endTurn(sender: UIButton!) { if coins.count > 0 { // @IBOutlet var coins: [UIButton]! (21 coins) let index: Int =…
Spartak
  • 41
  • 6
-1
votes
2 answers

Swift - arc4random() could not find an overload for '%' that accepts the supplied arguments

I have a UISlider to give a range of a radius of search (for 5 - x miles, max x=100 miles), and I want to be able to get a random radius distance within this range. @IBAction func sliderMoved(sender: UISlider){ //gives a range (minimum range 5…
Nick Nagy
  • 61
  • 4
-1
votes
4 answers

Quiz shows same questions

I have a quiz look-a-like app. It shows up all questions often. How can I make them show up only 1 time, and so after last question, a message will pop up? func nextText(){ let randomNumber = Int(arc4random_uniform(4)) var textLabel…
Torre Yan
  • 223
  • 3
  • 9
-1
votes
2 answers

Scaling arc4random for different screen sizes

I'm making a game that doesn't use Autolayout, and have used constraints to scale everything and it worked perfectly. However I cant seem to figure this out, I'm using arc4random to randomly position X and Y coordinates of a UIButton on the 4.7 inch…
-1
votes
2 answers

Randomizing object values without duplication

I'm creating a game with SpriteKit. I have 8 different colored balls positioned at 8 different designated CGPoints on the screen. Once the user gets to a certain score, I would like to randomize the colors of the balls to all be different colors,…
John
  • 23
  • 2
-1
votes
1 answer

Randomizing object positions without duplication or overlapping

I'm brand new to SpriteKit, and I'm creating a game that involves randomizing the CGPoint positions of objects on my screen when the user reaches certain score increments. I created a plist of the 8 set positions I want my objects to choose from…
Newbie
  • 164
  • 7
-1
votes
3 answers

How to simplify an extensive C if statement?

I am wondering what the best way is to approach this problem. I have a randomizing function set up that takes 8 strings as input and outputs a random one of them. I would like this randomizer to disregard all strings which have no value. For…
user1757682
  • 15
  • 1
  • 5
-1
votes
2 answers

How to use arc4random in JavaScript?

How do I use arc4random in JavaScript? I tried to use var randomNumber = (arc4random() % 83) + 1; but I got UncaughtReferenceError: arc4random is not defined. I am not sure which libs to include to use arc4random.
Gendaful
  • 5,522
  • 11
  • 57
  • 76
-2
votes
3 answers

Produced Numbers are must different each other with arc4random

i want to use arc4random but produced Numbers are must different each other. How do i do this example?
-2
votes
1 answer

IBOutlet with arc4random in swift3.0

i have code class ViewController: UIViewController { var detailText: String = "Chance of win is 50%" @IBOutlet weak var winChance: UILabel! func someMethod () -> Void { print("Method called!") } override func viewDidLoad() { …
-2
votes
1 answer

What does arc4random_uniform() do in a conditional?

This code passes 3 as an argument to the arc4random_uniform() function and I guess that it returns true or false. Next you assign an enumerator to a variable. I don't understand what the function does, though. let randomState =…
bensams127
  • 119
  • 1
  • 5
-2
votes
2 answers

Random number from 25 to 225 by 20 in c#?

How can I a random number from 25 to 225 by 20? For example: 25, 45 .65 ,85, 105 to 225?