views:

114

answers:

3

I have two numbers:

  1. IMEI Number : 12345678912345
  2. Random Pin : 654321

My Random pin changes always. Based on this combination (IMEI and PIN ) is there any way to generate a 6 digit random number?

I want to do it in C#.

+1  A: 

How about (IMEI + Pin) % 900000 + 100000?

Marcus Johansson
i like the mod 900000 plus 100000. not seen that before!
soniiic
+1  A: 

The most straightforward way is to seed the random number generator with a function of both numbers

Random r = new Random(IMEA+Pin);
int v = r.Next()%900000 + 100000;

in this example the function is just the sum but you can find something more senseful for sure.. it's just to give you the idea.

Jack
Compiler error... The best overloaded method match for 'System.Random.Random(int)' has some invalid arguments at line 1 column 12 Argument 1: cannot convert from 'long' to 'int' at line 1 column 23
soniiic
Random r = new Random(IMEA+Pin); Random number dosnt accept double it takes int as paramater... as IMEI + PIN is 19 digit number
Hasnain
Just modulo it to max bound of argument (int)(IMEA+Pin % int.Max)
Jack
+1  A: 

Fixed version of Jack's answer

int seed = unchecked((int)(imie+pin));
Random r = new Random(seed);
int[] result = new int[100];
for (int i = 0; i < 100; i++) {
    result[i] = r.Next() % 900000 + 100000;
}

edit fixed answer as per the sudden revelation that you need 100 numbers

soniiic