finding following random numbers in c++

Hi,
I have an assignment on c++, there are 1000 random numbers given, information says these numbers are generated by a mixed function as rand() of C++. So, what would be the next 10 random numbers?
I tried to use srand and reached a seed that finds similar random numbers to given ones. But teacher says a similar mixed function as rand, but not rand. So is there any algorithm or information any of you can give me about this? Is there a function that I dont know about in c++?
Deciphering the pattern of an RNG based on its output is, as far as I know, impossible unless the full period is exposed. I'm assuming that if you have 1000 numbers, then the period must be shorter than 1000, otherwise this assignment is lunacy.

Search through the random numbers and look for where they start to repeat. For a simplistic example:

9, 15, 4, 8, 9, 15, 4, 8, 9, 15, X, X, X

you'd know the next 3 numbers are 4, 8, 9 because the full period is exposed.

It is technically possible that there's a leader that isn't part of the full pattern:

4, 10, 5, 10, 5, 10, 5, 10

note the leading '4' that isn't part of the repeating period.

This generally doesn't happen (except in very poor RNGs), and I don't think your teacher would try to slip this in, so I wouldn't worry about it.
Last edited on
The problem is, it is not periodic. I mean, you can reach similar 1000 random numbers as giving srand the seed value 5400, and doing the rand() 1000 times, then there is the sequence I have, not exactly the same numbers though, but few dissimilarities. What am I suppose to do is to make those dissimilarities go away by c++, but I tried everything and I'm asking if there is something else I don't know or remember in c++ that can help me. or any mathematical information you know about.
Last edited on
Your teacher is a dick. There's an infinite number of answers to the question.
Last edited on
Thank you, I was about to get crazy, there are no answers for this question. Because of this, I won't graduate. I need this answer to pass the course and get diploma
I propose you ask this question back:
I thought these numbers up five minutes ago. There's no discernible pattern that connects them:
372, 36, 684384635, 1400, -17
What are the next n elements in the series?
The problem is, it is not periodic


All pRNGs are periodic. Including rand(), and whatever pRNG your assignment is using (provided it's using a pRNG, which, from your description, it is). It's just a matter of how big the period is. It probably isn't as small as 2 or 4, as my previous examples were, but might be a few hundred. Note that a number may repeat itself several times in the period -- so just because you ran into the same number twice doesn't mean you uncovered the entire period.

The way I understand this assignment, you should not be using rand() at all. It was just mentioned as a point of reference. It should have no use in the solution to this problem. There is no way to get rand() to start producing the same series of numbers you're receiving -- that's not how it works.

Look for the period... find the pattern. It has to be there. If it isn't, either:
a) we're misunderstanding this assignment
or
b) your instructor gave you an impossible assignment and/or is completely nuts.


EDIT:

Can you upload the numbers somewhere like googlepages or something so we can download it and look?

I really just don't believe your teacher gave you an impossible assignment.
Last edited on
I would also like to see the exact wording of the assignment.


The exact wording of the assignment;

The purpose in this assignment is to find 10 following numbers of given list with 1000 numbers. These 1000 numbers are generated by a mixed system just like the rand() routine of C++.

There are no more information given, I searched for a pattern, but no number is generated twice, so no periodicity. Thank you all or help so far.
Last edited on
*blinks in disbelief*

Did he say what a "mixed system" is supposed to be? Maybe something like "(seed*X)+Y" and you have to brute-force the algorithm to find X and Y. But that's completely absurd. Not to mention it has very little to do with learning C++ and a lot more to do with various fields of mathematics and statistics -- and unless that's stuff you've been covering in your course, this seems completely impractical that he'd expect you to do this. Your teacher really does seem to be a bonehead.
The original says "sistema mixto", which can alternatively be translated as "compound/combined system". In other words, the result of combining characteristics of two or more systems. I've never heard that term in my life. Google gives me nothing related to mathematics or computer science.

I've been on this for about ten minutes and found a possible link between 9 and 18963:
(9^2)^2*3=19683
It doesn't seem to apply to the rest, and doesn't explain why no value is longer than 15 bits. Plus, turning 19683 to 18963 is awkward.
If the formula is supposed to be anything like rand() (e.g. (((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff)), then the problem can very well be considered unsolvable.

EDIT: Well, I've already tested the formula N(i)=((N(i-1)*a+b)>>c)&0x7FFF for {n=2^16;a=[1;n];b=[0;n];c=[0;17]}, and I still haven't found a solution. Does anyone have time on a supercomputer to test n=2^32-1?
Last edited on
Topic archived. No new replies allowed.