I guess there will be some clue in the saved state file.Thomas Okken wrote: ↑Sun Feb 18, 2018 6:35 pmI tried changing shell_random_seed() so it always returns zero, but that causes a different sequence than the one produced by the DM42 after 0 SEED.
Random numbers
Re: Random numbers
-
- Posts: 1100
- Joined: Tue May 02, 2017 5:48 pm
- Location: Netherlands
- Contact:
Re: Random numbers
The saved state will only tell you what the seed was when the state was saved, not where that value came from...ijabbott wrote: ↑Mon Feb 19, 2018 9:39 pmI guess there will be some clue in the saved state file.Thomas Okken wrote: ↑Sun Feb 18, 2018 6:35 pmI tried changing shell_random_seed() so it always returns zero, but that causes a different sequence than the one produced by the DM42 after 0 SEED.
Re: Random numbers
Yes, but if you've set the seed but haven't generated any random numbers from it, it should provide a clue about the internal value (15 digit number) generated from the parameter of SEED. As I understand it, that internal value isn't generated by anything resembling a secure hash function, and should be partly reversible.Thomas Okken wrote: ↑Mon Feb 19, 2018 11:16 pmThe saved state will only tell you what the seed was when the state was saved, not where that value came from...ijabbott wrote: ↑Mon Feb 19, 2018 9:39 pmI guess there will be some clue in the saved state file.Thomas Okken wrote: ↑Sun Feb 18, 2018 6:35 pmI tried changing shell_random_seed() so it always returns zero, but that causes a different sequence than the one produced by the DM42 after 0 SEED.
-
- Posts: 1100
- Joined: Tue May 02, 2017 5:48 pm
- Location: Netherlands
- Contact:
Re: Random numbers
That's true. The initial seed is derived from the return value of shell_random_seed() as follows:ijabbott wrote: ↑Tue Feb 20, 2018 12:31 amYes, but if you've set the seed but haven't generated any random numbers from it, it should provide a clue about the internal value (15 digit number) generated from the parameter of SEED. As I understand it, that internal value isn't generated by anything resembling a secure hash function, and should be partly reversible.
seed = (abs(shell_random_seed()) % 1e14) * 10 + 1
The return value of shell_random_seed() is a signed 64-bit integer.
-
- Posts: 85
- Joined: Wed Jan 03, 2018 3:48 pm
- Location: Nuremberg, Germany
Re: Random numbers
Where can I find the seed, at which address? I've saved the machine state, opened it in a hex editor. But I have no clue where it's located.Thomas Okken wrote: ↑Tue Feb 20, 2018 11:34 amThat's true. The initial seed is derived from the return value of shell_random_seed() as follows:ijabbott wrote: ↑Tue Feb 20, 2018 12:31 amYes, but if you've set the seed but haven't generated any random numbers from it, it should provide a clue about the internal value (15 digit number) generated from the parameter of SEED. As I understand it, that internal value isn't generated by anything resembling a secure hash function, and should be partly reversible.
seed = (abs(shell_random_seed()) % 1e14) * 10 + 1
The return value of shell_random_seed() is a signed 64-bit integer.
DM15L S/# 10584 FW v25
DM42 S/# 01015 FW v3.5
DM42 S/# 01015 FW v3.5
-
- Posts: 1100
- Joined: Tue May 02, 2017 5:48 pm
- Location: Netherlands
- Contact:
Re: Random numbers
Look for occurrences of random_number_low and random_number_high in core_globals.cc (definition) and core_math2.cc (where they are used, in the math_random() function), or also in core_commands2.cc (where they are set, in the docmd_seed() function).
To help find those variables without knowing their addresses, use INPUT or EDITN with long, distinctive variable names; those names are stored in memory shortly before the random seed. Also, you can confirm you've found the seed by comparing it to the last number returned by RAN.
It would be a lot simpler for SwissMicros to simply fix shell_random_seed(), but until they come back from vacation and release their source code, this kind of old-school detective work is the best you can do to satisfy your curiosity, I'm afraid.
To help find those variables without knowing their addresses, use INPUT or EDITN with long, distinctive variable names; those names are stored in memory shortly before the random seed. Also, you can confirm you've found the seed by comparing it to the last number returned by RAN.
It would be a lot simpler for SwissMicros to simply fix shell_random_seed(), but until they come back from vacation and release their source code, this kind of old-school detective work is the best you can do to satisfy your curiosity, I'm afraid.
-
- Posts: 85
- Joined: Wed Jan 03, 2018 3:48 pm
- Location: Nuremberg, Germany
Re: Random numbers
"vacation" ... "vacation" ... hmmm, maybe Webster tells me what this is ...Thomas Okken wrote: ↑Tue Feb 20, 2018 1:52 pmLook for occurrences of random_number_low and random_number_high in core_globals.cc (definition) and core_math2.cc (where they are used, in the math_random() function), or also in core_commands2.cc (where they are set, in the docmd_seed() function).
To help find those variables without knowing their addresses, use INPUT or EDITN with long, distinctive variable names; those names are stored in memory shortly before the random seed. Also, you can confirm you've found the seed by comparing it to the last number returned by RAN.
It would be a lot simpler for SwissMicros to simply fix shell_random_seed(), but until they come back from vacation and release their source code, this kind of old-school detective work is the best you can do to satisfy your curiosity, I'm afraid.
Thanks for your help. I think I'll give it a try tonight.
Aaaaaah ... I love staying away some time for recreation, just to solve new problems when coming back to work *g*
DM15L S/# 10584 FW v25
DM42 S/# 01015 FW v3.5
DM42 S/# 01015 FW v3.5
-
- Posts: 1100
- Joined: Tue May 02, 2017 5:48 pm
- Location: Netherlands
- Contact:
Re: Random numbers
I thought you had decent amounts of paid vacation in Germany. Or does that not apply in Bavaria?Krauts In Space wrote: ↑Tue Feb 20, 2018 2:06 pm"vacation" ... "vacation" ... hmmm, maybe Webster tells me what this is ...
-
- Posts: 85
- Joined: Wed Jan 03, 2018 3:48 pm
- Location: Nuremberg, Germany
Re: Random numbers
Sure - unless you're an self-employed ...Thomas Okken wrote: ↑Tue Feb 20, 2018 2:43 pmI thought you had decent amounts of paid vacation in Germany. Or does that not apply in Bavaria?Krauts In Space wrote: ↑Tue Feb 20, 2018 2:06 pm"vacation" ... "vacation" ... hmmm, maybe Webster tells me what this is ...
DM15L S/# 10584 FW v25
DM42 S/# 01015 FW v3.5
DM42 S/# 01015 FW v3.5
Re: Random numbers
Here are the offsets of random_number_low and random_number_high in the state file (at least for firmware version 3.3):
There is one digit of overlap between random_number_high and random_number_low, i.e. the units digit of random_number_high is the same as the 10000000 digit of random_number_low (but only when seed is set via 0 SEED). So the line `s = s + 10 + 1;` produced the number 824188000174081 from 82418800017408.
So although we don't know the exact number returned by shell_random_seed(), we know its absolute value modulo 1e14 is 82418800017408.
- 0x16a random_number_low
- 0x172 random_number_high
- random_number_low = 174081
- random_number_high = 82418800
Code: Select all
if (x == 0) {
int8 s = shell_random_seed();
if (s < 0)
s = -s;
s %= 100000000000000LL;
s = s * 10 + 1;
random_number_high = s / 10000000LL;
random_number_low = s % 100000000LL;
return ERR_NONE;
}
So although we don't know the exact number returned by shell_random_seed(), we know its absolute value modulo 1e14 is 82418800017408.