Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common random number generator of iOS and Android

I need a Random Number Generator that produces same sequence of numbers both in iOS and Android if we give the same Seed in both.

I tried the rand() function with the srand(1000). But it gave different outputs. Then I tried mersenne twister. But that too gave difference sequence for same seed.

Could any one please help me on this.

I am using cocos2d-x for my development.

like image 345
Aaron Avatar asked Feb 08 '13 12:02

Aaron


People also ask

What is the most common random number?

The most random two-digit number is 37, When groups of people are polled to pick a “random number between 1 and 100”, the most commonly chosen number is 37. The Answer to the Ultimate Question of Life, the Universe, and Everything (“what is 6 times 9”, correct in base 13).

What is the most common random number between 1 and 20?

Proof that 17 is the most random number between 1 and 20. - YouTube.

Why is 17 the most common random number?

Seventeen is: Described at MIT as 'the least random number', according to the Jargon File. This is supposedly because in a study where respondents were asked to choose a random number from 1 to 20, 17 was the most common choice. This study has been repeated a number of times.


1 Answers

You can just write your own random number generator like this. The quality is low but will suit for most of the purpose.

// RAND_MAX assumed to be 32767.
static unsigned long int next = 1;
void srand(unsigned int seed) { next = seed; }
int rand(void) {
    next = next * 1103515245 + 12345;
    return (unsigned int)(next/65536) % 32768;
}
like image 104
Bryan Chen Avatar answered Oct 15 '22 23:10

Bryan Chen