Aside from the fact that this is obviously not well thought out, I do have a similar code for requests to a server in a personal project of mine. The line that creates the code looks like this (js):
var requestID = Math.random().toString(36).substring(2);
Converts the random number to base-36 (0-9 and A-Z) and trims off the 0. at the beginning. Used to match server responses to requests so that I can run code on the data used. Probably a terrible and insecure way of doing it but I don’t plan on the project seeing the light of day beyond maybe half a dozen people if I’m lucky so oh well.
Math.random() is still pseudorandom (and therefore predictable), the only random algorithm known that uses a camera overlooking a wall of lava lamps to determine the random output, which is only random because the behavior of the many lava lamps is generally unpredictable and you’d need to see them at the exact time they’re measured to get the randomness
But the difference is that Math.random() is going to generate a different sequence of random numbers every time you reboot your machine or application because it’s using your server’s pseudorandom generator source as seed. The code shown here uses 1000 as seed so the sequence of generated numbers is always the same. The original developer probably thought they were setting the upper range of the generated numbers instead of the seed, I guess.
I believe it's creating a random number generator with the seed 1000 and converting it to a string. Because the seed is always the same, it always spits out the same numbers.
A seed is used in the equation when creating a set of pseudo random numbers, normally something like the time is used so the generator seems "random".
The request token was parroted back as a way to link requests in the logs, so a random number wouldn’t be too terrible (except there was a better natural token that would make tracing through the logs easier).
However in vb.net, Random is only pseudorandom. So if you seed it with the same seed, the same sequence of numbers comes out. Since the code was always seeding the Random class with the same seed (1000 in this case) the first “random” number generated is always the same.
I found this little fun piece of code in our production legacy winforms app written in vb.net while trying to track something through the logs and not finding it.
This is in the production desktop app. One of the sections I haven’t totally ripped out and reworked so there isn’t direct sql access on a single dB connection opened when the application starts then just assumed to be open till the application ends in the 20k loc windows form class
67
u/bb1950328 Sep 02 '21
is 12488 the line number?
3
u/DumbMuscle Sep 02 '21
This is just https://xkcd.com/221/ with extra steps
7
u/Kotentopf Sep 02 '21
Guid.NewGuid()
5
u/pavilionhp_ learning from the best Sep 02 '21
Aside from the fact that this is obviously not well thought out, I do have a similar code for requests to a server in a personal project of mine. The line that creates the code looks like this (js):
Converts the random number to base-36 (0-9 and A-Z) and trims off the
0.at the beginning. Used to match server responses to requests so that I can run code on the data used. Probably a terrible and insecure way of doing it but I don’t plan on the project seeing the light of day beyond maybe half a dozen people if I’m lucky so oh well.5
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Sep 02 '21
Image Transcription: Code
[This line of code is on line
12488in the file.]I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
0
u/[deleted] Sep 01 '21
[deleted] — view deleted comment
0
u/[deleted] Sep 02 '21
[deleted] — view deleted comment