1

I'm creating an implementation of a Lindenmayer system (L-system) in the Clojure programming language and I'm trying to figure out a name for a utility function which takes a number of arguments and then, using uniform distribution, chooses one of them. I'd like to appeal to non-mathematical/non-statistical readers by using a succinct function name which does not stray too far from the average person's vocabulary (soft goal, I know). Right now I've settled for "one-of", but I wonder if there is a more correct and easily understood term I could use.

By the way, if anyone wants to see the code in context, it is here: https://github.com/Reefersleep/l-mayer/blob/master/src/l_mayer/core.clj

The function implementation looks like this:

(defn one-of
  [& args]
  (let [random (rand-int (count args))]
    (get args random)))

And can be used like this:

(one-of :a :b :c)

In this usage, it would return either :a, :b or :c, with a 33,3% chance of each.

  • I'm voting to close this question as off-topic because naming functions is off topic – Matt E. Эллен Feb 4 '16 at 13:04
  • 1
    @matt-e-Эллен Where is this documented ? I had a look at english.stackexchange.com/help/on-topic and english.stackexchange.com/help/dont-ask and thought this question falls safely into "Word choice and usage" ? – k1eran Feb 4 '16 at 15:01
  • Maybe it was a faux paus to mention why I was interested in knowing what a layman's term for "uniform distribution" is , because so far, no one has attempted to answer it - rather, they relate their answers to the code. Though I appreciate these efforts, I am still interested in an answer to the original question and recognise that code naming may be off topic. I could edit the answer or reask it without mentioning the code aspect at all? – Reefersleep Feb 4 '16 at 16:08
  • 1
    @k1eran if you look more closely in "on topic", naming things is in the off topic section. – Matt E. Эллен Feb 5 '16 at 11:16
  • @Reefersleep Our single-word-requests tag description (click "learn more") gives a good outline for how to ask this sort of question. Feel free to edit this question to apply to those rules. – Matt E. Эллен Feb 5 '16 at 11:18
0

See https://stackoverflow.com/a/388128/449347 where they use pick-random for a similar Clojure function.

Also that question has various other function names e.g. choose.

I don't think this question is a total duplicate however, as this one is primarily about function naming, whereas the stack-overflow one is about function implementation/coding.

  • I appreciate the trove of suggestions in that thread :) And I may end up using something in that vein. But if possible, I would like to express the statistical aspect of "uniform distribution". – Reefersleep Feb 4 '16 at 16:11
0

If you primary goal is clarity then I would use a longer function name like returnOneRandomArgument.

If you don't think that connotes the uniform distribution idea, then maybe pickOneArgumentFromHat would work.

  • I think both of your suggestions relate to the randomness, but not in a clear enough way to the idea of uniform distribution - the relatable aspect of "from hat" is good, but I think it is misleading in a code context, where it could be misconstrued as a side effect. – Reefersleep Feb 4 '16 at 16:16
  • @Reefersleep: I understand your concern. However, I think that to the layman "random" automatically means "random with a uniform distribution". Perhaps you might work the word "bias" or "unbiased" into the function name (pickOneWithoutBias)? I'm not sure that would make it any clearer though. – James Feb 4 '16 at 17:10
  • I think you're right about "random" implying uniform distribution. Perhaps such a thing as a layman's term for explicit uniform distribution in a random selection does not make sense because it is normally implied. Adding "bias" is a good suggestion, but taking the above into account, I think it would be better to leave it out. – Reefersleep Feb 5 '16 at 14:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.