Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I saw the following code in this commit for MongoDB's Java Connection driver, and it appears at first to be a joke of some sort. What does the following code do?

if (!((_ok) ? true : (Math.random() > 0.1))) {

return res; 

}

1 Answer

0 votes
by (106k points)

The reason why MongoDB Java driver uses a random number generator in a conditional because the surrounding negation and excessive parentheses convolute things further. Keeping in mind De Morgan's laws it is a trivial observation that this piece of code amounts to

if (!_ok && Math.random() <= 0.1) 

return res;

Related questions

0 votes
1 answer
asked Sep 5, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
asked Feb 7, 2020 in Web Technology by ashely (50.2k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...