Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #16359
| Newsgroups | comp.programming |
|---|---|
| Date | 2023-01-31 06:14 -0800 |
| References | <86cz6wfz88.fsf@linuxsc.com> |
| Message-ID | <a815fddb-13e7-48ff-93f7-c86ecc13b2a9n@googlegroups.com> (permalink) |
| Subject | Re: Programming exercise - choose_k_of_n_then_select() |
| From | Julio Di Egidio <julio@diegidio.name> |
On Monday, 30 January 2023 at 05:00:45 UTC+1, Tim Rentsch wrote:
<snip>
> Problem: rng is a random number generator function that returns
> values uniformly distributed between 0 and rng_max, inclusive (so
> rng_max+1 possible values. Choose k+1 distinct random values (using
> the supplied function rng) in the range between 0 and n, inclusive
> (so n+1 possible values).
That rng_max is really an error since it introduces a double step
that does not exist in reality (if you can instantiate an rng for the
range [0,rng_max], then you can as well directly instantiate one
for the range [0,n]). The requirement indeed boils down to
generating k+1 random numbers in the range [0,n]. If your intent,
as I guess, was to have one explicitly code the transformation of
range, you should have asked for an rng that (as usual) returns
numbers in [0,1[.
> Of these k+1 distinct values, return the
> j'th value in ascending order (so for j=0 return the least value,
> for j=k return the largest value, etc).
I don't think better can be done than:
1. loop to generate the random numbers
1.*. insert sorted into a containing array (ascending)
2. return the j-th element of the array.
Julio
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar
Programming exercise - choose_k_of_n_then_select() Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-01-29 20:00 -0800
Re: Programming exercise - choose_k_of_n_then_select() Paul N <gw7rib@aol.com> - 2023-01-30 06:01 -0800
Re: Programming exercise - choose_k_of_n_then_select() Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-01-30 07:48 -0800
Re: Programming exercise - choose_k_of_n_then_select() c186282 <c186282@nnada.net> - 2025-06-13 23:18 -0400
Re: Programming exercise - choose_k_of_n_then_select() Julio Di Egidio <julio@diegidio.name> - 2023-01-31 06:14 -0800
Re: Programming exercise - choose_k_of_n_then_select() Y A <air000000000000@ya.ee> - 2023-02-10 06:38 -0800
csiph-web