![]() |
help me name this function
What's a good name for a random number function which
receives an int (n) and returns a random int (uniform distribution) 0..n-1? That's quite useful in C. For example to choose a random array element like: element = array[rng_n(ARRAY_SIZE)] rng_n() is the current name of my function, I am trying to find a more meaningful name... |
Re: help me name this function
On 22/02/11 23:02, copx wrote:
> What's a good name for a random number function which > receives an int (n) and returns a random int > (uniform distribution) 0..n-1? > > That's quite useful in C. For example to choose a random array element > like: > > element = array[rng_n(ARRAY_SIZE)] > > rng_n() is the current name of my function, I am trying > to find a more meaningful name... > > I have two suggestions for you: 1) unsigned int discrete_uniform(unsigned int); 2) off_t opic(int his_newsgroup); /* need to #include <sys/types.h> */ -E -- 'sane', adj.: see 'unimaginative' on the web - http://jttlov.no-ip.org |
Re: help me name this function
"ec429" wrote in message news:ik1fuf$5dd$1@news.eternal-september.org... >I have two suggestions for you: >1) unsigned int discrete_uniform(unsigned int); Unfortunately, my rng lib has multiple functions which are based on discrete uniform distribution, in fact all functions are based on it and thus this needs no explicit mentioning. I am mostly trying to find a good expression for "0..n-1" here. |
Re: help me name this function
"copx" <c...@gazeta.pl> wrote:
> What's a good name for a random number function which > receives an int (n) and returns a random int > (uniform distribution) 0..n-1? I call mine randN(). -- Peter |
Re: help me name this function
Sherm Pendley <sherm.pendley@gmail.com> writes:
> "copx" <copx@gazeta.pl> writes: >> "ec429" wrote in message >> news:ik1fuf$5dd$1@news.eternal-september.org... >>>I have two suggestions for you: >>>1) unsigned int discrete_uniform(unsigned int); >> >> Unfortunately, my rng lib has multiple functions which >> are based on discrete uniform distribution, in fact all functions >> are based on it and thus this needs no explicit mentioning. I am >> mostly trying to find a good expression for "0..n-1" here. > > dN(), based on the traditional RPG die expressions of d6, d10, d20, > etc. Not bad -- except that RGP dice are typically 1-based (d6 is 1..6, etc.). I think I've seen the name "randn" for this kind of thing. -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
Re: help me name this function
"Keith Thompson" wrote in message news:lnsjvftsey.fsf@nuthaus.mib.org... >I think I've seen the name "randn" for this kind of thing. I guess I will use rng_n() then ("rng_" is the namespace prefix here). I kinda hoped there was a technical term for "0..n-1". |
Re: help me name this function
"Sherm Pendley" wrote in message news:m2ipwbmste.fsf@sherm.shermpendley.com... >> mostly trying to find a good expression for "0..n-1" here. > >dN(), based on the traditional RPG die expressions of d6, d10, d20, >etc. I don't see the logic behind that, "d6" means 1..6, not 0..5. Also I already have a random dice funtion: rng_dice(n_dice, n_sides) in the same module/namespace. |
Re: help me name this function
"copx" <copx@gazeta.pl> writes:
> "Keith Thompson" wrote in message > news:lnsjvftsey.fsf@nuthaus.mib.org... >>I think I've seen the name "randn" for this kind of thing. > > I guess I will use rng_n() then ("rng_" is the namespace prefix > here). I kinda hoped there was a technical term for "0..n-1". Well in a way there is. If the function's return type is unsigned it is simply "less than n". Another closely related technical term is "modulo n". (This does not rule out the other equivalence classes as being the returned set (for example n..2n-1) but 0..n-1 is considered canonical.) When a function takes one argument, I am not averse to using a name that refers to the argument, so I'd consider things like 'rand_less_than' and 'rng_mod' because they read reasonably well. ('mod' is a well-known contraction of 'modulo'.) -- Ben. |
Re: help me name this function
On Feb 23, 1:02*am, "copx" <c...@gazeta.pl> wrote:
> > rng_n() is the current name of my function, I am trying > to find a more meaningful name... > randi. It's reasonably short, and the i indicates that it's integral. Everyone expects a uniform distribution, so you don't need to spell it out in the name. I use uniform() for a random float 0 - 1-epsilon and coin() for a boolean 0 or 1, though I return it as an int. |
Re: help me name this function rng_mod(AREA_WIDTH) rng_less_than(AREA_WIDTH)
"Ben Bacarisse" wrote in message news:0.453352d3b54eee861763.20110223122423GMT.87ip wb547c.fsf@bsb.me.uk... >When a function takes one argument, I am not averse to using a name that >refers to the argument, so I'd consider things like 'rand_less_than' and >'rng_mod' because they read reasonably well. ('mod' is a well-known >contraction of 'modulo'.) Thanks, those are some good suggestions. I will use rng_mod(n), problem solved! |
| All times are GMT. The time now is 09:34 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.