Synchronize with server?

Hello,

I must preface what I'm about to ask by saying that, while this technically is a programming question, I thought that the lounge would be the most appropriate place to post this, because it isn't specifically related to C++. I chose to ask this question on this forum, because I'm sure there are some tech savvy people who can help me (and I'm not familiar with any other forums). If this is all wrong, I'll remove this thread. My question has more to do with web programming, which is a subject that I'm very unfamiliar with, so it's likely that I might not make sense.

Here's my question:

I'd like to send a request to a server/website to retrieve the server/website time.
This particular server/website is running(?) javascript. It makes use of the Math.random() function, which seems to be seeded with System.currentTimeMillis(), which returns the number of milliseconds which have elapsed since Midnight of January 1, 1970 UTC.
The reason I'd like to do this, is because this particular website generates certain pseudo-random numbers, which I'd like to be able to predict.
How would I go about doing this? I guess the real question is if there's anyone here who has any experience with this sort of thing? I've read that the implementations of Javascript functions are dependent on the browser and operating system, which could be an issue. I'd like to slap together a C++ solution because that's what I'm comfortable with, but like I said I have no idea what I'm getting in to. I'm not even entirely sure which questions to ask.
Last edited on
This particular server/website is running(?) javascript
Serverside or clientside?
It makes use of the Math.random() function, which seems to be seeded with System.currentTimeMillis()
Are you sure? What makes you think that? If it is serverside, is it global state, it it seeded once per session, is it seeded on each page creation? What random generator are they use?
Sorry for not providing enough info.

Serverside or clientside?

From what little I know, I believe it's server-side.

Are you sure? What makes you think that?

I'm actually not sure, but I have a hunch. By inspecting the page elements, I was able to locate some jscript files (.js), which are client side. To be more precise, the website actually generates two sets of numbers - one client-side (which I can analyze because I have the .js files), and one set of server-side (I assume they're server side, because I cannot find any reference to these numbers or their creation in any of the .js files). However, it's actually the client-side numbers which are being generated with Math.random, but the client and server numbers are so similar that it leads me to believe that they are generated in the exact same way. Like I said, it's a gamble.

If it is serverside, is it global state, it it seeded once per session, is it seeded on each page creation?


That's a good question. Is there a way of finding out?

What random generator are they use?

The first answer on this thread was the only real documentation I could find.
http://stackoverflow.com/questions/13301839/predict-the-seed-of-javascripts-math-random

The first answer on this thread was the only real documentation I could find.
FIrst answer mentions that it checked Rhino library. If they are using it, it might be still valid. If they not... Let's say that 4 major web browsers are using different random generator implementations.

That's a good question. Is there a way of finding out?
Sure thing. Get a hold on source code and find out.

However, it's actually the client-side numbers which are being generated with Math.random,
If you are using one of the open-source browsers, download its source codeand do modification to the JS library so random will give numbers you need.

but the client and server numbers are so similar that it leads me to believe that they are generated in the exact same way
Define 'similar'
To be more precise:

I'm not actually looking for numbers, so to speak.

The server (I think, because I can't see it in the .js) creates one twelve character string.
The client (I think, because I can see it in the .js) creates one sixteen character string.

So, it's not really numbers I'm after. It's really the seed of the PRNG of when it created the server string.
I'm not sure I should give away the details of how the string is created using the PRNG, but I can say that
both the client string and the server string are composed of the same alphanumeric character set (A-Z, a-z, 0-9).
It's this fact that leads me to believe that they are created in the same way. Of course, there's no way of knowing if that's true. The only noticeable difference is of course the content of the strings, and the fact that they are different lengths.

The client string changes every time I quit the browser and check back again, so I guess that gets seeded every session.

The server string changes every time I push a certain button.

I'll either edit this post, or post another post tomorrow. I've been trying to figure this out all day, and my brain is fried and I can't think straight.
I do appreciate your help, MiiniPaa.
Last edited on
are composed of the same alphanumeric character set (A-Z, a-z, 0-9).
It's this fact that leads me to believe that they are created in the same way
It has nothing to do with generation. First random number is generated then it feded by randon distribution function which transforms it to one letter. Repeas as needed.

Without knowing exact algorithm used, exact seeding parameter, exact usage (warm-up sequences, how and where are new numbers generated...) you can not predict results of generation.
I know it has nothing to do with it, which is why I said it was a hunch, and which is why I also said that there's no way of knowing.
Topic archived. No new replies allowed.