Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given a RNG algorithm and a series of numbers is it possible to determine what seed would produce the series?

The code is in Objective C but it should be understandable if you look it over even if you don't know Objective C. Basically its a RNG object, you instantiate a new instance, set the seed if you want and start grabbing random numbers.

So is it possible to backtrack a given series of numbers to determine the seed used to generate the numbers? I'm guessing any given algorithm can't generate just any random set of numbers though, or can it?

Say I do the following:

rng.seed = 1024;
for (int i=1; i<11; i++)
    DLog(@"%lu", [rng randomBetween:0 and:10]);

Which gives me the sequence 10, 10, 8, 10, 2, 10, 9, 9, 7, 4. Is there some method or algorithm I could use, given the sequence, to get the number 1024? I know thats the valid sequence for the seen 1024, but what is I just make up a sequence... 10, 1, 9, 6, 3, 9, 10, 3, 5, 2. Is there a way to know if that is a valid sequence for this algorithm and if so what the seed is?

RNG.h:

@interface RNG : NSObject
@property (assign) unsigned long seed;
- (unsigned long)random;
- (long)randomBetween: (long)min and: (long)max;
@end

RNG.m:

#define A 16807         /* a relatively prime number -- also M div Q */
#define M 2147483647L   /* 0xFFFFFFFF / 2 */
#define Q 127773L       /* M div A */
#define R 2836          /* M mod A */

@implementation RNG
@synthesize seed = _seed;

- (id)init {
    self = [super init];
    if (self) {
        self.seed = 0;
    }
    return self;
}


- (unsigned long)random {
    self.seed = A * (self.seed % Q) - R * (self.seed / Q);
    if (self.seed > M)
        return (self.seed -= M);
    else if (self.seed)
        return (self.seed);
    else
        return (self.seed = 1L);
}


- (long)randomBetween: (long)min and: (long)max {
    return ([self random] % (max - min + 1) + min);
}


- (void)seed: (unsigned long)new_seed {
    if (new_seed == 0)
        new_seed = 1;
    while (new_seed > M)
        new_seed -= M;

    self.seed = new_seed;
}
@end
like image 268
Justin808 Avatar asked Aug 16 '12 08:08

Justin808


People also ask

How do I find my RNG seed?

import sys import random l = [11.1, 22.2, 33.3, 11.1, 33.3, 33.3, 22.2, 55.5] for i in range(10): seed = random. randrange(sys. maxsize) print("Seed:", seed) random. seed(seed) l_new = random.

What is seed in RNG?

When you use statistical software to generate random numbers, you usually have an option to specify a random number seed. A seed is a positive integer that initializes a random-number generator (technically, a pseudorandom-number generator). A seed enables you to create reproducible streams of random numbers.

What happens if the same seed value is always used for generating random numbers?

A pseudorandom number generator's number sequence is completely determined by the seed: thus, if a pseudorandom number generator is reinitialized with the same seed, it will produce the same sequence of numbers.

Is it possible to calculate RNG?

If the purpose of your algorithm search is to synthesize the sequence that already passed, then yes it's possible. If the purpose of your algorithm search is to predict the next number, then no.


1 Answers

This looks like a "Linear congruential generator", see http://en.wikipedia.org/wiki/Linear_congruential_generator" ?

These offer no good cryptographic security, so yes, it should be possible to compute a seed that produces the sequence.

like image 62
mgaert Avatar answered Sep 20 '22 06:09

mgaert