6
\$\begingroup\$

I recently asked this question: Random value excluding both limits

The code to review is as follows:

do {
    var random = Math.random();
} while(random === 0);

I know it is short and looks like stub code, but it actually is my real live code to generate the random number. I did not simplify it, I did not modify it. I copy-pasted it from my original code.

Now the question is put on hold as off topic with this reason given:

"Questions must involve real code that you own or maintain. Pseudocode, hypothetical code, or stub code should be replaced by a concrete example. Questions seeking an explanation of someone else's code are also off-topic."

In my opinion, this reason is not valid. The code, although very short, is real and I want to know if there are any unintended effects from using a loop to generate the random value.

My question also clearly states my question:

Is there any downside to using this snippet

Reading the comments to the question, it seems the decision whether the question is off topic or not is a little opinion based.

Why exactly is this question considered off topic? How would it have to be modified to be on topic?

\$\endgroup\$
10
\$\begingroup\$

I don't see any reason for the question to be considered off-topic. The task is well-defined, and your concrete implementation works. Applying the same reasoning as for another question with a short code snippet, I've reopened your question.

\$\endgroup\$
4
\$\begingroup\$

I voted as such initially and later retracted my vote.

At first sight it looks like example code. Even like a feature request, a stub or a 'how should I do this'. All of those would be off-topic. However, I came to agree with you it could very well be real code with perhaps a skewed explanation.

Janos explained it better in the comments under your question:

@LarsEbert your question is really "Is this the correct way to generate a reasonably uniform distribution of random floats in the range (0, 1) (bounds excluded) ?" It's an interesting question, but it's not a code review question. Your question is not about the general quality of your code, but very specifically about one narrow area of generating uniformly distributed random numbers. Random numbers are extremely tricky, and I doubt you will find here the kind of authoritative answer you seem to be looking for. – janos

That's a very good point. Code Review is about reviewing code. If you would've written it as 'this is what I got, should I do it differently' it may very well have been accepted without trouble.

In summary: Your question as stated may or may not be off-topic, but not (only) for the reasons stated.

\$\endgroup\$
  • \$\begingroup\$ @janos Discussing the quality of the random-number-generating technique is on-topic for Code Review too. \$\endgroup\$ – 200_success Jul 3 '15 at 9:54
  • \$\begingroup\$ @200_success so then this is on-topic too?codereview.stackexchange.com/q/95723/12390 \$\endgroup\$ – janos Jul 3 '15 at 21:48
  • 1
    \$\begingroup\$ @janos It's more marginal, since it is asking for a proof of pseudo-randomness. Note that that poster has a problematic track record, and the link is rather spammy. \$\endgroup\$ – 200_success Jul 3 '15 at 21:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .