Retired
Can you predict Math.random()? (retired)
Loading description...
Puzzles
Mathematics
Algorithms
Logic
Numbers
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Also, because of how you sequence the actions in the test cases nasty hacks like this solution is possible:
https://www.codewars.com/kata/reviews/582ff32539f6540e78000033/groups/596dba1509eecd8336000a46
I fixed that, I belive it is not possible anymore.
The kata author is not even trying.
Its very simle, test case passes, random test case passes, submission throws error, TypeError: random is not a function at Object.handleError at ContextifyScript.Script.runInThisContext at Object.exports.runInThisContext
"Hacking the JavaScript Lottery" was interesting read. Thanks for bringing it up :)
This kata looks really time consuming, so I'd like to make sure if I'm understanding correctly before starting.
In order to solve this kata, we have to:
src/base/utils/random-number-generator.{cc,h}
and figure out how to recover random bits from random double^
,<<
,>>>
,&
,+
)XorShift128+
andNextDouble()
XorShift128+
with constraint comparing lower bits of symbolically generated and the actualstate0
andstate1
using lower 52 bits from consecutive outputs ofMath.random
random
as a function generating double fromXorShift128+
withstate0
andstate1
Is this correct interpretation?
Also, how are you ensuring that
Math.random
is not called anywhere else?random
using sharedMath.random
, how are you ensuring that nothing else calls it? I mean what if the Codewars test framework or some module used by the test framework usesMath.random
?random
in completely isolated context (as invm.createContext
), how are you ensuringMath.random
inTest.assertEquals(random(), Math.random());
to equalMath.random
that was used?edit: reworded & cleaned up
Never mind. I missed the comment by @Testerinhio for some reason :|
But you asked very good question. Probably tests are not using Math.random() but as I cant be sure about that, I changed testing code to avoid problem you described.
I just skimmed through the new example test.
First, this doesn't call
random
at all becauserunTests
is0
.Second, I don't think this changes anything. Placing tests inside IIFE does not avoid the problem I described.
Math.random
inside it still references the same globalMath.random
. IIFE creates new evaluation scope within the same execution context.@gkucmierz: You have not solved it yourself?!?! You only have your hack to get this kata published?
Hey, is it illegal? I have no time to do this now, but I know it is possible and it is very interesting kata in my opinion.
BTW. how you can see my sources? I cant see your solution.
This comment has been hidden.
This comment has been hidden.