+ 17
Explanation cookietition: Not so random numbers
Can you explain why these codes don't generate random numbers? Examples are taken from https://www.javacodegeeks.com/2011/10/weird-funny-java.html First one who solves this gets a cookie ^^ https://code.sololearn.com/c34w8Lly3T3Z/?ref=app https://code.sololearn.com/cLtBhvREvi9x/?ref=app
37 ответов
+ 12
found some more "funky seeds"
-45134723714L
441287210
-39344509274L
-39907010362L
-47948021285L
-44652557061L
-45278129360L
-39925487530L
-45778109653L
-42574820846L
-43695896529L
-24503459995L
+ 15
OK, it took me some time... But here's the explanation of the outputs, step by step:
https://code.sololearn.com/cK4LC20JHf48/?ref=app
+ 14
The challenge outcookies:
5 cookies -> @Burey
5 cookies -> @Pixie
5 cookies -> @Annatoli
4 cookies -> @jay
4 cookies -> @Krishna
4 cookies -> @Manual
3 cookies -> @Steven
3 cookies -> @Suhal
... and the rest of the cookies half to Burey and half to Hatsy Rei who provided supplies ;)
+ 13
ooo I dont drink java.. no cookies for me
+ 13
odd that all of funky seeds found by burey are negative longs except one. which is a positive int.
+ 13
' 🕊
/ \
/ \
/ \
/ \
🍪🍪🍪🍪🍪
🍪🍪🍪🍪🍪
🍪🍪🍪🍪🍪
🍪🍪🍪🍪🍪
🍪🍪🍪🍪🍪
+ 12
@jay Correct!
🍪->@jay
And why do you need this?
+ 12
@jay
Only the seeds are different...
+ 11
@Manual Yes, it does ^^
But why? What is the parameter? And why is it possible to use it there? When could it be useful?
( I provide one cookie out of Burey's stash for the answer, more if you complete it ^^)
🍪->@Manual
+ 10
here's the promised cookie stash :D
🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪🍪
jay: 🍪
Manual: 🍪
+ 10
lol cheeky.. in #1 the seed will always return one as it is the same seed for each in the loop.
Manual.. thanks
+ 10
printin has something to do with #2 as that is the only real difference I can see..m
+ 10
heheh i can give it to manual. he made it click for me
+ 10
whats the L in the seed?
+ 10
@Burey Yeah, the solution is in there ^^
setSeed method does that...
Does someone want to explain what's happening there with the two different seeds - to earn the solution cookies?
+ 8
Random Class source code for reference:
http://developer.classpath.org/doc/java/util/Random-source.html
+ 8
@Burey and Tashi: In my humble opinion in order to generate a real random number, you need to exclude recursion as much as possible. Using a constant and it doesn't matter if it is gaussian or whatever will generate repetitive numbers shortly. If however you select your seeds (two of them at least) from a algorithm combined from system date and time, the chance of duplication is minimal because the date changes every day and never comes back.
Using generation of two seeds and double genaration of the random number you're excluding further the duplication then if you would use just a single pass to generate your random number. I'm still in the progress learning the correct syntaxis on both C++ and C# and even Java and it is quite confusing at times. So I better spend some more time on C++.
Nobody needs to agree with my solution, but I just want to point out, that generating a real random number is not that easy, and using a seed number from a constant or series of constants isn't the solution at all. Recursion will occur sooner than you might think. Even the creators of Electronic gaming machines face this problem, but then they rather have control over the random generation for their commercial interests.
+ 8
@Annatoli. This is a puzzle.
+ 8
@Steven: I did read the article that your provided in the link, but I guess this is some bridges to far for the purpose that we are addressing here. They point out several interesting theories, and even refer to my suggestion that you need to include some real world data to generate a seed that should provide a random number as close as possible. However, nothing is obsolete so generation of a random number should be simple but adequate enough for the average person or user to be setup in an application.
Sure we can go on and on on this matter, but still there will be more than enough theoretical sinergy to keep a discussion going on forever. This was not my intention at all. So for me, this matter is closed until ........... Thank you all for your input guy's this shows that SoloLearn is a live and kicking! Keep it up !
+ 7
println makes no diff.
Both programs look the same. lol