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.
Asked
Active
Viewed 632 times
-1

Michael Petrotta
- 59,888
- 27
- 145
- 179

Gendaful
- 5,522
- 11
- 57
- 76
2 Answers
4
arc4random()
is not defined in JavaScaript. To generate random numbers in JavaScript you can use Math.random()
. But I think you can easy emulate arc4random()
as:
function arc4random(){
return Math.random()*4294967296;
}

Andrew D.
- 8,130
- 3
- 21
- 23
1
I do not believe it possible, given all research points to the fact that arc4random is not a js function, but one built in to objective-c, or ios. I'm beginning to believe you did little research into the matter. Even the tag wiki entry on SO says as much.

Daedalus
- 7,586
- 5
- 36
- 61
-
Agree. Even I did not find any pointers for this function in javascript. – Gendaful May 17 '12 at 05:28