Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

A Fortran compiler is the hobgoblin of little minis.


devel / comp.lang.c / Re: Compute Unique Numbers in a Set

SubjectAuthor
* Compute Unique Numbers in a SetAlbert
+* Re: Compute Unique Numbers in a SetChris M. Thomasson
|`* Re: Compute Unique Numbers in a SettTh
| `- Re: Compute Unique Numbers in a SetChris M. Thomasson
+* Re: Compute Unique Numbers in a SetRichard Damon
|`* Re: Compute Unique Numbers in a SetBen Bacarisse
| `* Re: Compute Unique Numbers in a SetRichard Damon
|  `* Re: Compute Unique Numbers in a SetBen Bacarisse
|   `* Re: Compute Unique Numbers in a SetRichard Damon
|    `* Re: Compute Unique Numbers in a SetBen Bacarisse
|     `* Re: Compute Unique Numbers in a SetRichard Damon
|      `* Re: Compute Unique Numbers in a SetBen Bacarisse
|       `* Re: Compute Unique Numbers in a SetRichard Damon
|        `* Re: Compute Unique Numbers in a SetBen Bacarisse
|         `* Re: Compute Unique Numbers in a SetRichard Damon
|          `* Re: Compute Unique Numbers in a SetBen Bacarisse
|           `* Re: Compute Unique Numbers in a SetRichard Damon
|            `- Re: Compute Unique Numbers in a SetBen Bacarisse
+- Re: Compute Unique Numbers in a SetTim Rentsch
+* Re: Compute Unique Numbers in a SetBen Bacarisse
|+* Re: Compute Unique Numbers in a SetMike Terry
||`- Re: Compute Unique Numbers in a SetBen Bacarisse
|`- Re: Compute Unique Numbers in a SetTim Rentsch
+- Re: Compute Unique Numbers in a SetManu Raju
+* Re: Compute Unique Numbers in a Setantispam
|`* Re: Compute Unique Numbers in a SetRichard Damon
| +* Re: Compute Unique Numbers in a SetTim Rentsch
| |`- Re: Compute Unique Numbers in a SetRichard Damon
| `- Re: Compute Unique Numbers in a Setantispam
+- Re: Compute Unique Numbers in a Setjak
+* Re: Compute Unique Numbers in a SetRosario19
|`- Re: Compute Unique Numbers in a SetRosario19
+* Re: Compute Unique Numbers in a SetKenny McCormack
|+* Re: Compute Unique Numbers in a Setjak
||+- Re: Compute Unique Numbers in a Setjak
||`* Re: Compute Unique Numbers in a SetTim Rentsch
|| `- Re: Compute Unique Numbers in a SetÖö Tiib
|`- Re: Compute Unique Numbers in a SetKenny McCormack
+- Re: Compute Unique Numbers in a SetBart
+* Re: Compute Unique Numbers in a SetStefan Ram
|`* Re: Compute Unique Numbers in a SetRichard Damon
| `* Re: Compute Unique Numbers in a SetBen Bacarisse
|  +- Re: Compute Unique Numbers in a SetRichard Damon
|  +- Re: Compute Unique Numbers in a SetSiri Cruise
|  +- Re: Compute Unique Numbers in a SetTim Rentsch
|  +- Re: Compute Unique Numbers in a SetDavid Brown
|  `* Re: Compute Unique Numbers in a SetTim Rentsch
|   `* Re: Compute Unique Numbers in a SetKenny McCormack
|    `- Re: Compute Unique Numbers in a SetDavid Brown
+* Re: Compute Unique Numbers in a SetBonita Montero
|+- Re: Compute Unique Numbers in a SetBonita Montero
|+* Re: Compute Unique Numbers in a SetKenny McCormack
||`* Re: Compute Unique Numbers in a SetBonita Montero
|| +* Re: Compute Unique Numbers in a SetBonita Montero
|| |+* Re: Compute Unique Numbers in a SetBart
|| ||+* Re: Compute Unique Numbers in a SetBonita Montero
|| |||`* Re: Compute Unique Numbers in a SetBart
|| ||| `* Re: Compute Unique Numbers in a SetBonita Montero
|| |||  `* Re: Compute Unique Numbers in a SetBart
|| |||   `- Re: Compute Unique Numbers in a SetBonita Montero
|| ||`* Re: Compute Unique Numbers in a SetBart
|| || `* Re: Compute Unique Numbers in a SetIke Naar
|| ||  `* Re: Compute Unique Numbers in a SetBart
|| ||   `- Re: Compute Unique Numbers in a SetChris M. Thomasson
|| |+- Re: Compute Unique Numbers in a SetPaavo Helde
|| |`* Re: Compute Unique Numbers in a SetAlf P. Steinbach
|| | `* Re: Compute Unique Numbers in a SetBonita Montero
|| |  +- Re: Compute Unique Numbers in a SetMalcolm McLean
|| |  +* Re: Compute Unique Numbers in a SetBen Bacarisse
|| |  |`* Re: Compute Unique Numbers in a SetMalcolm McLean
|| |  | +* Re: Compute Unique Numbers in a SetMalcolm McLean
|| |  | |`* Re: Compute Unique Numbers in a SetBen Bacarisse
|| |  | | `* Re: Compute Unique Numbers in a SetMalcolm McLean
|| |  | |  `* Re: Compute Unique Numbers in a SetBen Bacarisse
|| |  | |   `- Re: Compute Unique Numbers in a SetMalcolm McLean
|| |  | `- Re: Compute Unique Numbers in a SetBen Bacarisse
|| |  `* Re: Compute Unique Numbers in a SetBonita Montero
|| |   +- Re: Compute Unique Numbers in a SetMalcolm McLean
|| |   +* Re: Compute Unique Numbers in a SetKenny McCormack
|| |   |`* Re: Compute Unique Numbers in a SetBonita Montero
|| |   | `* Re: Compute Unique Numbers in a SetKenny McCormack
|| |   |  `* Re: Compute Unique Numbers in a SetBonita Montero
|| |   |   `- Re: Compute Unique Numbers in a SetKenny McCormack
|| |   `* Re: Compute Unique Numbers in a SetBonita Montero
|| |    +* Re: Compute Unique Numbers in a SetBart
|| |    |`- Re: Compute Unique Numbers in a SetBonita Montero
|| |    `- Re: Compute Unique Numbers in a SetKenny McCormack
|| `* Re: Compute Unique Numbers in a SettTh
||  `* Re: Compute Unique Numbers in a SetBonita Montero
||   `- Re: Compute Unique Numbers in a SetKenny McCormack
|`- Re: Compute Unique Numbers in a SetChris M. Thomasson
+- Re: Compute Unique Numbers in a SetBen Bacarisse
`- Re: Compute Unique Numbers in a SetJohn Forkosh

Pages:1234
Re: Compute Unique Numbers in a Set

<toh5oi$1bg0$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24134&group=comp.lang.c#24134

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!ergjzcLR3BzwP2XzheD4Og.user.46.165.242.91.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Wed, 28 Dec 2022 11:28:36 +0100
Organization: Aioe.org NNTP Server
Message-ID: <toh5oi$1bg0$1@gioia.aioe.org>
References: <todbqe$16sg$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="44544"; posting-host="ergjzcLR3BzwP2XzheD4Og.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Thunderbird
X-Notice: Filtered by postfilter v. 0.9.2
 by: jak - Wed, 28 Dec 2022 10:28 UTC

Il 27/12/2022 00:45, Albert ha scritto:
> Is this the best way to generate unique random numbers in a set of 6
> numbers?
>
>
> <******************************************************>
>
> void generateNumbers()
> {
> int val1, val2, val3, val4, val5, val6;
>
> val1 = rand() % 59 + 1;
> printf("%4d", val1);
>
> val2 = rand() % 59 + 1;
> while (val2 == val1)
> {
> val2 = rand() % 59 + 1;
> }
> printf("%4d", val2);
>
> val3 = rand() % 59 + 1;
> while (val3 == val1 || val3 == val2)
> {
> val3 = rand() % 59 + 1;
> }
> printf("%4d", val3);
>
> val4 = rand() % 59 + 1;
> while (val4 == val1 || val4 == val2 || val4 == val3)
> {
> val4 = rand() % 59 + 1;
> }
> printf("%4d", val4);
>
> val5 = rand() % 59 + 1;
> while (val5 == val1 || val5 == val2 || val5 == val3 || val5 == val4)
> {
> val5 = rand() % 59 + 1;
> }
> printf("%4d", val5);
>
> val6 = rand() % 59 + 1;
> while (val6 == val1 || val6 == val2 || val6 == val3 || val6 == val4
> || val6 == val5)
> {
> val6 = rand() % 59 + 1;
> }
> printf("%4d", val6);
> printf("\n");
> }
> <******************************************************>
>
> The main prog using this function:
> #include <stdio.h>
> #include <stdlib.h>
> #include<windows.h>
>
> int main(void)
> {
> for (int i = 0; i < 100; i++)
> {
> generateNumbers();
> Sleep(1000);
> }
> return 0;
> }

using a lookup table?

void generateNumbers()
{ char num_flag[61];
int val[6];

memset(num_flag, '\0', sizeof(num_flag));

for(int i = 0; i < 6; i++)
{
while(num_flag[val[i] = rand() % 59 + 1]);
num_flag[val[i]] = 1;
}

printf("\n");
for(int i = 0; i < 6; i++)
printf("%d ", val[i]);
printf("\n");
}

Re: Compute Unique Numbers in a Set

<87mt77j741.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24136&group=comp.lang.c#24136

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Thu, 29 Dec 2022 02:06:54 +0000
Organization: A noiseless patient Spider
Lines: 121
Message-ID: <87mt77j741.fsf@bsb.me.uk>
References: <todbqe$16sg$1@gioia.aioe.org> <r8sqL.106906$iU59.104545@fx14.iad>
<87a638n8kj.fsf@bsb.me.uk> <DTEqL.146517$gGD7.19214@fx11.iad>
<87sfh0lr50.fsf@bsb.me.uk> <iTFqL.10904$OD18.573@fx08.iad>
<87h6xglom6.fsf@bsb.me.uk> <Y7HqL.20387$wfQc.14603@fx43.iad>
<87bknolie2.fsf@bsb.me.uk> <HCIqL.374481$GNG9.98817@fx18.iad>
<874jtgkzft.fsf@bsb.me.uk> <CdPqL.95542$Tcw8.10688@fx10.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="6b84fea570a3b418e6a9903ca8a2c4d6";
logging-data="134788"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Z62v1jvRrhCI9zAK2h2x5S+p71EfyR4Y="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:JPG7hCZqvRS1lhSuyYaMbrpDjGc=
sha1:2FDWLZxdZUgSAJUDGx6/Os6iRsY=
X-BSB-Auth: 1.b6b78e960570449929bd.20221229020654GMT.87mt77j741.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 29 Dec 2022 02:06 UTC

Richard Damon <Richard@Damon-Family.org> writes:

> On 12/27/22 9:57 PM, Ben Bacarisse wrote:
>> Richard Damon <Richard@Damon-Family.org> writes:
>>
>>> On 12/27/22 3:08 PM, Ben Bacarisse wrote:
>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>
>>>>> On 12/27/22 12:53 PM, Ben Bacarisse wrote:
>>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>>
>>>>>>> On 12/27/22 11:59 AM, Ben Bacarisse wrote:
>>>>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>>>>
>>>>>>>>> On 12/27/22 10:57 AM, Ben Bacarisse wrote:
>>>>>>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>>>>>>
>>>>>>>>>>> On 12/26/22 6:45 PM, Albert wrote:
>>>>>>>>>>>> Is this the best way to generate unique random numbers in a set of 6
>>>>>>>>>>>> numbers?
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> An alternate way to generate numbers without repeat, and avoid
>>>>>>>>>>> recalling the random number generator, is first generate the number
>>>>>>>>>>> between 0 and N-1,
>>>>>>>>>>>
>>>>>>>>>>> Then generate the second number between 0 and N-2, and if the result
>>>>>>>>>>> is greater than or equal the first number, increment it.
>>>>>>>>>>>
>>>>>>>>>>> Then generate the third number between 0 and N-3, and if the result is
>>>>>>>>>>> greater than or equal to the first number, increment it. THen if it is
>>>>>>>>>>> greater than or equal to the second number, increment it.
>>>>>>>>>>>
>>>>>>>>>>> Just keep repeating the pattern with smaller and smaller ranges, and
>>>>>>>>>>> compare to the previous numbers in order, and increment if the value
>>>>>>>>>>> at that point is greater than or equoal.
>>>>>>>>>> I don't see how this does the job at all. For example, when picking 3
>>>>>>>>>> from, say, [0,5] we might pick 2 and then 1. Now if the third choice is
>>>>>>>>>> 1 it is not equal to 2 (so no increment) but it is equal to 1 so
>>>>>>>>>> increment to 2.
>>>>>>>>>
>>>>>>>>> As I think about it, if you increment, you need to restart the scan
>>>>>>>>> with the beginning number, but not repeat a test. Another way is have
>>>>>>>>> a sorted list of picks and work smallest to largest.
>>>>>>>>>
>>>>>>>>> So:
>>>>>>>>>
>>>>>>>>> #1
>>>>>>>>> From [0, 5] get 2
>>>>>>>>>
>>>>>>>>> #2
>>>>>>>>> From [0, 4] get 1
>>>>>>>>> 1 not >= 2 so ok.
>>>>>>>>>
>>>>>>>>> #3
>>>>>>>>>
>>>>>>>>> From [0, 3] get 1
>>>>>>>>> 1 not >= 2 so next
>>>>>>>>> 1 IS >= 1 so make 2 and restart
>>>>>>>>> 1 >= 2 so make 3
>>>>>>>> Presumably "2 >= 2 so make 3"
>>>>>>>>
>>>>>>>>> don't repeat test 2.
>>>>>>>> Now you just get highly biased results (if I've got then hang of it).
>>>>>>>>
>>>>>>>
>>>>>>> No, it is unbiased, we skip the test of the second number, as that
>>>>>>> rule was already used for this number.
>>>>>>
>>>>>> What's the algorithm, then? My attempt to code it from your description
>>>>>> must have gone wrong.
>>>>>
>>>>> You choose a random number based on the number of UNCHOSEN numbers
>>>>> left.
>>>> Can you give the algorithm using some pseudo code?
>>>>
>>>>> since they weren't all the lowest numbers, you increase the value by
>>>>> one for every chosen value that is less than or equal to the number
>>>>> picked (including after any other increases).
>>>> Surely it's a few lines of pseudo code. I'm getting lost in the words.
>>>
>>> simplest version, which keeps a temp sorted array.
>>>
>>> function non_repeating_random_range(
>>> int npick, // number of picks to make
>>> int nchoice, // range of choices
>>> int* randoms): // array to return the answers in
>>>
>>> int ordered_list[npick]; // List of picks in acending order
>>> for i in 0 to npick-1
>>> random = random_number(nchoice-i); // Random unpicked slot
>>> for element in urdered_list:
>>> if random >= element: random++
>>> else break from loop
>>> *randoms++ = random;
>>> insert random into ordered_list
>> OK, I see what you were getting at.
>> That seems a little more fussy than Floyd's algorithm using a set:
>> set<int> S = {}
>> for j = nchoice - npick + 1 to nchoice
>> r = random_int(j) + 1
>> insert into S (if r in S then j else r)
>
> Because his method first only generates a "Set", which appears to not
> remember the order of insertion

I don't know what this "because" relates to.

> He is generating a random combination, not a random (partial)
> permutation. The original program seemed to make a distinction. The
> question comes is the answer 1, 2, 3, 4, 5 different than 5, 4, 3, 2,
> 1 ?
>
> If his set tries to remember order, then the first element CAN'T be
> from the whole set, as the random_int for that isn't from the whold
> nchoice option.

I'm lost again.

--
Ben.

Re: Compute Unique Numbers in a Set

<lV8rL.67445$t5W7.17482@fx13.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24138&group=comp.lang.c#24138

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx13.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Subject: Re: Compute Unique Numbers in a Set
Newsgroups: comp.lang.c
References: <todbqe$16sg$1@gioia.aioe.org> <r8sqL.106906$iU59.104545@fx14.iad>
<87a638n8kj.fsf@bsb.me.uk> <DTEqL.146517$gGD7.19214@fx11.iad>
<87sfh0lr50.fsf@bsb.me.uk> <iTFqL.10904$OD18.573@fx08.iad>
<87h6xglom6.fsf@bsb.me.uk> <Y7HqL.20387$wfQc.14603@fx43.iad>
<87bknolie2.fsf@bsb.me.uk> <HCIqL.374481$GNG9.98817@fx18.iad>
<874jtgkzft.fsf@bsb.me.uk> <CdPqL.95542$Tcw8.10688@fx10.iad>
<87mt77j741.fsf@bsb.me.uk>
From: Rich...@Damon-Family.org (Richard Damon)
Content-Language: en-US
In-Reply-To: <87mt77j741.fsf@bsb.me.uk>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 160
Message-ID: <lV8rL.67445$t5W7.17482@fx13.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Wed, 28 Dec 2022 23:42:57 -0500
X-Received-Bytes: 7791
 by: Richard Damon - Thu, 29 Dec 2022 04:42 UTC

On 12/28/22 9:06 PM, Ben Bacarisse wrote:
> Richard Damon <Richard@Damon-Family.org> writes:
>
>> On 12/27/22 9:57 PM, Ben Bacarisse wrote:
>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>
>>>> On 12/27/22 3:08 PM, Ben Bacarisse wrote:
>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>
>>>>>> On 12/27/22 12:53 PM, Ben Bacarisse wrote:
>>>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>>>
>>>>>>>> On 12/27/22 11:59 AM, Ben Bacarisse wrote:
>>>>>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>>>>>
>>>>>>>>>> On 12/27/22 10:57 AM, Ben Bacarisse wrote:
>>>>>>>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>>>>>>>
>>>>>>>>>>>> On 12/26/22 6:45 PM, Albert wrote:
>>>>>>>>>>>>> Is this the best way to generate unique random numbers in a set of 6
>>>>>>>>>>>>> numbers?
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> An alternate way to generate numbers without repeat, and avoid
>>>>>>>>>>>> recalling the random number generator, is first generate the number
>>>>>>>>>>>> between 0 and N-1,
>>>>>>>>>>>>
>>>>>>>>>>>> Then generate the second number between 0 and N-2, and if the result
>>>>>>>>>>>> is greater than or equal the first number, increment it.
>>>>>>>>>>>>
>>>>>>>>>>>> Then generate the third number between 0 and N-3, and if the result is
>>>>>>>>>>>> greater than or equal to the first number, increment it. THen if it is
>>>>>>>>>>>> greater than or equal to the second number, increment it.
>>>>>>>>>>>>
>>>>>>>>>>>> Just keep repeating the pattern with smaller and smaller ranges, and
>>>>>>>>>>>> compare to the previous numbers in order, and increment if the value
>>>>>>>>>>>> at that point is greater than or equoal.
>>>>>>>>>>> I don't see how this does the job at all. For example, when picking 3
>>>>>>>>>>> from, say, [0,5] we might pick 2 and then 1. Now if the third choice is
>>>>>>>>>>> 1 it is not equal to 2 (so no increment) but it is equal to 1 so
>>>>>>>>>>> increment to 2.
>>>>>>>>>>
>>>>>>>>>> As I think about it, if you increment, you need to restart the scan
>>>>>>>>>> with the beginning number, but not repeat a test. Another way is have
>>>>>>>>>> a sorted list of picks and work smallest to largest.
>>>>>>>>>>
>>>>>>>>>> So:
>>>>>>>>>>
>>>>>>>>>> #1
>>>>>>>>>> From [0, 5] get 2
>>>>>>>>>>
>>>>>>>>>> #2
>>>>>>>>>> From [0, 4] get 1
>>>>>>>>>> 1 not >= 2 so ok.
>>>>>>>>>>
>>>>>>>>>> #3
>>>>>>>>>>
>>>>>>>>>> From [0, 3] get 1
>>>>>>>>>> 1 not >= 2 so next
>>>>>>>>>> 1 IS >= 1 so make 2 and restart
>>>>>>>>>> 1 >= 2 so make 3
>>>>>>>>> Presumably "2 >= 2 so make 3"
>>>>>>>>>
>>>>>>>>>> don't repeat test 2.
>>>>>>>>> Now you just get highly biased results (if I've got then hang of it).
>>>>>>>>>
>>>>>>>>
>>>>>>>> No, it is unbiased, we skip the test of the second number, as that
>>>>>>>> rule was already used for this number.
>>>>>>>
>>>>>>> What's the algorithm, then? My attempt to code it from your description
>>>>>>> must have gone wrong.
>>>>>>
>>>>>> You choose a random number based on the number of UNCHOSEN numbers
>>>>>> left.
>>>>> Can you give the algorithm using some pseudo code?
>>>>>
>>>>>> since they weren't all the lowest numbers, you increase the value by
>>>>>> one for every chosen value that is less than or equal to the number
>>>>>> picked (including after any other increases).
>>>>> Surely it's a few lines of pseudo code. I'm getting lost in the words.
>>>>
>>>> simplest version, which keeps a temp sorted array.
>>>>
>>>> function non_repeating_random_range(
>>>> int npick, // number of picks to make
>>>> int nchoice, // range of choices
>>>> int* randoms): // array to return the answers in
>>>>
>>>> int ordered_list[npick]; // List of picks in acending order
>>>> for i in 0 to npick-1
>>>> random = random_number(nchoice-i); // Random unpicked slot
>>>> for element in urdered_list:
>>>> if random >= element: random++
>>>> else break from loop
>>>> *randoms++ = random;
>>>> insert random into ordered_list
>>> OK, I see what you were getting at.
>>> That seems a little more fussy than Floyd's algorithm using a set:
>>> set<int> S = {}
>>> for j = nchoice - npick + 1 to nchoice
>>> r = random_int(j) + 1
>>> insert into S (if r in S then j else r)
>>
>> Because his method first only generates a "Set", which appears to not
>> remember the order of insertion
>
> I don't know what this "because" relates to.

Do you understand the difference between a "List" and a "Set"

A List has the POTENTIAL of dupicate entries, and keeps track of order.

A Set (normally) can't hold duplicate entries, and doesn't keep track of
order.

The Set {1, 2, 3, 4} is the exact same Set as {4, 3, 2, 1}
but the list [1, 2, 3, 4] isn't the same as [4, 3, 2, 1]

Floyd's program give just a random Set of numbers (perhaps becuase the
OP used the term "Set" in an informal manner to express his problem. It
does NOT generate a uniform answer if the order was important.

>
>> He is generating a random combination, not a random (partial)
>> permutation. The original program seemed to make a distinction. The
>> question comes is the answer 1, 2, 3, 4, 5 different than 5, 4, 3, 2,
>> 1 ?
>>
>> If his set tries to remember order, then the first element CAN'T be
>> from the whole set, as the random_int for that isn't from the whold
>> nchoice option.
>
> I'm lost again.
>

Floyd's program is based on math that assumes it doesn't matter what
order the numbers are in, that the results are just considered a "Set"
that doesn't consider the order of the numbers to be important.

In Math, these sorts of assortments are often called combitorals. In
combitorial math, STAR and RATS are "The Same" as they use the same SET
of letters, so they are the same results of selecting 4 letters out of
the alphabet.

Permutations keep track of order, so STAR and RATS are different answers.

A simple point to note, Floyd's generator when taking 6 picks out of 59
symbols will NEVER chose the number 59 as its first pick, so it does NOT
generate permutations with uniform distribution. In fact, the ONLY pick
that can have the value of 59 will be the last one, but that one will
have a 6/59 chance of being 59.

When treated as a combination, so order doesn't matter, the sets do turn
out to be uniformly distrbuted.

Ultimately, the question comes did the OP think order mattered or not.

Re: Compute Unique Numbers in a Set

<87358yjsz4.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24139&group=comp.lang.c#24139

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Thu, 29 Dec 2022 12:26:55 +0000
Organization: A noiseless patient Spider
Lines: 168
Message-ID: <87358yjsz4.fsf@bsb.me.uk>
References: <todbqe$16sg$1@gioia.aioe.org> <r8sqL.106906$iU59.104545@fx14.iad>
<87a638n8kj.fsf@bsb.me.uk> <DTEqL.146517$gGD7.19214@fx11.iad>
<87sfh0lr50.fsf@bsb.me.uk> <iTFqL.10904$OD18.573@fx08.iad>
<87h6xglom6.fsf@bsb.me.uk> <Y7HqL.20387$wfQc.14603@fx43.iad>
<87bknolie2.fsf@bsb.me.uk> <HCIqL.374481$GNG9.98817@fx18.iad>
<874jtgkzft.fsf@bsb.me.uk> <CdPqL.95542$Tcw8.10688@fx10.iad>
<87mt77j741.fsf@bsb.me.uk> <lV8rL.67445$t5W7.17482@fx13.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="6b84fea570a3b418e6a9903ca8a2c4d6";
logging-data="338883"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183C76CzcAZBk6BqyknK0uVMd6JnWW6Bp0="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:zRxUJNgmd0mpQA8BNH5VZJ0idco=
sha1:1RDMlqeTc3h1PQDAedb8vjUUKy8=
X-BSB-Auth: 1.508915368cd8e0ca1dfe.20221229122655GMT.87358yjsz4.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 29 Dec 2022 12:26 UTC

Richard Damon <Richard@Damon-Family.org> writes:

> On 12/28/22 9:06 PM, Ben Bacarisse wrote:
>> Richard Damon <Richard@Damon-Family.org> writes:
>>
>>> On 12/27/22 9:57 PM, Ben Bacarisse wrote:
>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>
>>>>> On 12/27/22 3:08 PM, Ben Bacarisse wrote:
>>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>>
>>>>>>> On 12/27/22 12:53 PM, Ben Bacarisse wrote:
>>>>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>>>>
>>>>>>>>> On 12/27/22 11:59 AM, Ben Bacarisse wrote:
>>>>>>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>>>>>>
>>>>>>>>>>> On 12/27/22 10:57 AM, Ben Bacarisse wrote:
>>>>>>>>>>>> Richard Damon <Richard@Damon-Family.org> writes:
>>>>>>>>>>>>
>>>>>>>>>>>>> On 12/26/22 6:45 PM, Albert wrote:
>>>>>>>>>>>>>> Is this the best way to generate unique random numbers in a set of 6
>>>>>>>>>>>>>> numbers?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> An alternate way to generate numbers without repeat, and avoid
>>>>>>>>>>>>> recalling the random number generator, is first generate the number
>>>>>>>>>>>>> between 0 and N-1,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Then generate the second number between 0 and N-2, and if the result
>>>>>>>>>>>>> is greater than or equal the first number, increment it.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Then generate the third number between 0 and N-3, and if the result is
>>>>>>>>>>>>> greater than or equal to the first number, increment it. THen if it is
>>>>>>>>>>>>> greater than or equal to the second number, increment it.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Just keep repeating the pattern with smaller and smaller ranges, and
>>>>>>>>>>>>> compare to the previous numbers in order, and increment if the value
>>>>>>>>>>>>> at that point is greater than or equoal.
>>>>>>>>>>>> I don't see how this does the job at all. For example, when picking 3
>>>>>>>>>>>> from, say, [0,5] we might pick 2 and then 1. Now if the third choice is
>>>>>>>>>>>> 1 it is not equal to 2 (so no increment) but it is equal to 1 so
>>>>>>>>>>>> increment to 2.
>>>>>>>>>>>
>>>>>>>>>>> As I think about it, if you increment, you need to restart the scan
>>>>>>>>>>> with the beginning number, but not repeat a test. Another way is have
>>>>>>>>>>> a sorted list of picks and work smallest to largest.
>>>>>>>>>>>
>>>>>>>>>>> So:
>>>>>>>>>>>
>>>>>>>>>>> #1
>>>>>>>>>>> From [0, 5] get 2
>>>>>>>>>>>
>>>>>>>>>>> #2
>>>>>>>>>>> From [0, 4] get 1
>>>>>>>>>>> 1 not >= 2 so ok.
>>>>>>>>>>>
>>>>>>>>>>> #3
>>>>>>>>>>>
>>>>>>>>>>> From [0, 3] get 1
>>>>>>>>>>> 1 not >= 2 so next
>>>>>>>>>>> 1 IS >= 1 so make 2 and restart
>>>>>>>>>>> 1 >= 2 so make 3
>>>>>>>>>> Presumably "2 >= 2 so make 3"
>>>>>>>>>>
>>>>>>>>>>> don't repeat test 2.
>>>>>>>>>> Now you just get highly biased results (if I've got then hang of it).
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> No, it is unbiased, we skip the test of the second number, as that
>>>>>>>>> rule was already used for this number.
>>>>>>>>
>>>>>>>> What's the algorithm, then? My attempt to code it from your description
>>>>>>>> must have gone wrong.
>>>>>>>
>>>>>>> You choose a random number based on the number of UNCHOSEN numbers
>>>>>>> left.
>>>>>> Can you give the algorithm using some pseudo code?
>>>>>>
>>>>>>> since they weren't all the lowest numbers, you increase the value by
>>>>>>> one for every chosen value that is less than or equal to the number
>>>>>>> picked (including after any other increases).
>>>>>> Surely it's a few lines of pseudo code. I'm getting lost in the words.
>>>>>
>>>>> simplest version, which keeps a temp sorted array.
>>>>>
>>>>> function non_repeating_random_range(
>>>>> int npick, // number of picks to make
>>>>> int nchoice, // range of choices
>>>>> int* randoms): // array to return the answers in
>>>>>
>>>>> int ordered_list[npick]; // List of picks in acending order
>>>>> for i in 0 to npick-1
>>>>> random = random_number(nchoice-i); // Random unpicked slot
>>>>> for element in urdered_list:
>>>>> if random >= element: random++
>>>>> else break from loop
>>>>> *randoms++ = random;
>>>>> insert random into ordered_list
>>>> OK, I see what you were getting at.
>>>> That seems a little more fussy than Floyd's algorithm using a set:
>>>> set<int> S = {}
>>>> for j = nchoice - npick + 1 to nchoice
>>>> r = random_int(j) + 1
>>>> insert into S (if r in S then j else r)
>>>
>>> Because his method first only generates a "Set", which appears to not
>>> remember the order of insertion
>> I don't know what this "because" relates to.
>
> Do you understand the difference between a "List" and a "Set"

Seriously?

> A List has the POTENTIAL of dupicate entries, and keeps track of order.
>
> A Set (normally) can't hold duplicate entries, and doesn't keep track of order.
>
> The Set {1, 2, 3, 4} is the exact same Set as {4, 3, 2, 1}
> but the list [1, 2, 3, 4] isn't the same as [4, 3, 2, 1]
>
> Floyd's program give just a random Set of numbers (perhaps becuase the
> OP used the term "Set" in an informal manner to express his
> problem. It does NOT generate a uniform answer if the order was
> important.

Of course I understand all that.

>>> He is generating a random combination, not a random (partial)
>>> permutation. The original program seemed to make a distinction. The
>>> question comes is the answer 1, 2, 3, 4, 5 different than 5, 4, 3, 2,
>>> 1 ?
>>>
>>> If his set tries to remember order, then the first element CAN'T be
>>> from the whole set, as the random_int for that isn't from the whold
>>> nchoice option.
>> I'm lost again.
>>
>
> Floyd's program is based on math that assumes it doesn't matter what
> order the numbers are in, that the results are just considered a "Set"
> that doesn't consider the order of the numbers to be important.
>
> In Math, these sorts of assortments are often called combitorals. In
> combitorial math, STAR and RATS are "The Same" as they use the same
> SET of letters, so they are the same results of selecting 4 letters
> out of the alphabet.
>
> Permutations keep track of order, so STAR and RATS are different answers.
>
> A simple point to note, Floyd's generator when taking 6 picks out of
> 59 symbols will NEVER chose the number 59 as its first pick, so it
> does NOT generate permutations with uniform distribution. In fact, the
> ONLY pick that can have the value of 59 will be the last one, but that
> one will have a 6/59 chance of being 59.
>
> When treated as a combination, so order doesn't matter, the sets do
> turn out to be uniformly distrbuted.
>
> Ultimately, the question comes did the OP think order mattered or not.


Click here to read the complete article
Re: Compute Unique Numbers in a Set

<tokqrr$19r4$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24140&group=comp.lang.c#24140

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!NZ87pNe1TKxNDknVl4tZhw.user.46.165.242.91.POSTED!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Thu, 29 Dec 2022 19:47:07 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <tokqrr$19r4$1@gioia.aioe.org>
References: <todbqe$16sg$1@gioia.aioe.org> <tog6cb$pq4$1@gioia.aioe.org> <CDNqL.140231$iS99.60763@fx16.iad>
Injection-Info: gioia.aioe.org; logging-data="42852"; posting-host="NZ87pNe1TKxNDknVl4tZhw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: tin/2.4.5-20201224 ("Glen Albyn") (Linux/5.10.0-9-amd64 (x86_64))
Cancel-Lock: sha1:h3R+9YOm2u4yM8vOb57MKWc6gSs=
X-Notice: Filtered by postfilter v. 0.9.2
 by: antis...@math.uni.wroc.pl - Thu, 29 Dec 2022 19:47 UTC

Richard Damon <Richard@damon-family.org> wrote:
> On 12/27/22 8:32 PM, antispam@math.uni.wroc.pl wrote:
> > Albert <invalid@gmail.com> wrote:
> >> Is this the best way to generate unique random numbers in a set of 6
> >> numbers?
> >
> > "unique random numbers in a set of 6 numbers" is strange formulation
> > of the problem. In such a small set you get at most 6 numbers
>
> No, it is a classical problem, the physical model is drawing from a
> sack/bag without replacement.

Problem of "drawing without replacement" is classic. Formulating
this as "unique random numbers in a set of 6 numbers" is strange.

> > without repeating. If you want exactly 6, this is (random) permutation
> > of original numbers. There is standard, resonably efficient
> > algoritm for generating random permutations of N elements. Assuming
> > numbering starting from 1, as step 1, swap number at first position N
> > with number at random postion (if random position happens to be N this
> > is a no-op). Then recursively do generate random permutation of positions
> > 1 to N - 1. This is easy to implement as a loop, but presentation
> > is simpler in recursive way.
> >
> > If you need less numbers than N, then you can use firs k < N positions
> > of random permutation. Different methods make sense only if size
> > of your set (that in N) is much larger than number of random numbers
> > that you need (that is k). For N = 6 there is no reason to do
> > anything more complicated than generating random permutation.
> >
>
> The issue with the permutation methods is you need to set up the "bag"
> of ALL POSSIBLE numbers. In this case, 60 isn't THAT big, so not so
> much of an issue. If the "bag" (the universe being selected from) gets
> much larger, creating a copy of that set to do the permutation set
> becomes a lot of extra work that isn't needed.

Yes, this is different wording of what I wrote.

> If you are drawing a signifcant fraction of the set, then it becomes
> more reasonable.
>
> Note, in this case N = *60* and *k* = 6 (we are drawing 6 numbers from
> the set of 60, not out of just 6 numbers. Yes, the OP was a bit sloppy
> with his words, but from the code they gave, their intent was clear.

I admit that code looked so crappy that I did not want to analyse
it. And to say the truth, my approch is: first say clearly what
should be done, then code this. Without clear statement of intent
one never know if some irregularity is a bug or a feature.

--
Waldek Hebisch

Re: Compute Unique Numbers in a Set

<h8p3rhdn49ih0ef2t16gjcag95i6itg57k@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24152&group=comp.lang.c#24152

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Ros...@invalid.invalid (Rosario19)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Sun, 01 Jan 2023 21:06:50 +0100
Organization: A noiseless patient Spider
Lines: 91
Message-ID: <h8p3rhdn49ih0ef2t16gjcag95i6itg57k@4ax.com>
References: <todbqe$16sg$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader01.eternal-september.org; posting-host="ce8e154e6f70014e1c42f1e8c55f54d4";
logging-data="1583098"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PbChxJkbCdVNHbgyPZhUYOXpZASXDdUM="
Cancel-Lock: sha1:qiuBV3GFX3LhtwWYtKzXZHfTCYU=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Rosario19 - Sun, 1 Jan 2023 20:06 UTC

On Mon, 26 Dec 2022 23:45:04 +0000, Albert <invalid@gmail.com> wrote:

>Is this the best way to generate unique random numbers in a set of 6
>numbers?
>
>
><******************************************************>
>
>void generateNumbers()
>{
> int val1, val2, val3, val4, val5, val6;
>
> val1 = rand() % 59 + 1;
> printf("%4d", val1);
>
> val2 = rand() % 59 + 1;
> while (val2 == val1)
> {
> val2 = rand() % 59 + 1;
> }
> printf("%4d", val2);
>
> val3 = rand() % 59 + 1;
> while (val3 == val1 || val3 == val2)
> {
> val3 = rand() % 59 + 1;
> }
> printf("%4d", val3);
>
> val4 = rand() % 59 + 1;
> while (val4 == val1 || val4 == val2 || val4 == val3)
> {
> val4 = rand() % 59 + 1;
> }
> printf("%4d", val4);
>
> val5 = rand() % 59 + 1;
> while (val5 == val1 || val5 == val2 || val5 == val3 || val5 == val4)
> {
> val5 = rand() % 59 + 1;
> }
> printf("%4d", val5);
>
> val6 = rand() % 59 + 1;
> while (val6 == val1 || val6 == val2 || val6 == val3 || val6 == val4
>|| val6 == val5)
> {
> val6 = rand() % 59 + 1;
> }
> printf("%4d", val6);
> printf("\n");
>}
><******************************************************>
>
>The main prog using this function:
>#include <stdio.h>
>#include <stdlib.h>
>#include<windows.h>
>
>int main(void)
>{
> for (int i = 0; i < 100; i++)
> {
> generateNumbers();
> Sleep(1000);
> }
> return 0;
>}

int array[6];

int*f(void)
{int i,j,c,t;
for(i=0;i<6;++i) array[i]=0;
srand((unsigned int)time(0));
for(c=0;c<10;++c)
{i=rand()%6; j=rand()%6;
if(i!=j){t=array[i];array[i]=array[j];array[j]=t;}
}
return array;
}

int main(void)
{int i, *a ;
a=f();
for(i=0;i<6;++i) printf("%d ", a[i]);
printf("\n");
return 0;
}

Re: Compute Unique Numbers in a Set

<tot4eh$21qv0$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24153&group=comp.lang.c#24153

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Sun, 1 Jan 2023 23:19:46 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tot4eh$21qv0$1@news.xmission.com>
References: <todbqe$16sg$1@gioia.aioe.org>
Injection-Date: Sun, 1 Jan 2023 23:19:46 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2157536"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sun, 1 Jan 2023 23:19 UTC

In article <todbqe$16sg$1@gioia.aioe.org>, Albert <invalid@gmail.com> wrote:
>Is this the best way to generate unique random numbers in a set of 6
>numbers?
>
>
><******************************************************>

Here's my contribution to this thread.

Note that this is both gcc- and Linux- specific, as well as being
hard-coded to OP's problem specification. Note also that I took the
liberty of assuming that OP actually, really, did want random numbers
between 0 and 59; this would be suitable if, say, OP was looking for a
random number of minutes or seconds (and we could be talking either about
time intervals or about locations/distances expressed in terms of latitude
and/or longitude).

--- Cut Here ---
#include <stdio.h>
#include <stdint.h>

int main(void)
{ uint64_t num = 0, j = 1;
FILE *fp = fopen("/dev/urandom","r");

while (__builtin_popcount(num) < 6)
num |= 1 << (fgetc(fp) % 60);

for (int i=0; i<60; i++, j *= 2)
if (num & j)
printf("i = %d, j = %ld\n",i,j);
return 0;
} --- Cut Here ---

The values printed out of the variable "i" are your random numbers.

--
People who say they'll vote for someone else because Obama couldn't fix
*all* of Bush's messes are like people complaining that he couldn't cure
cancer, so they'll go and vote for (more) cancer.

Re: Compute Unique Numbers in a Set

<3kr4rh961jlpj71qardijadvfitbs189sn@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24154&group=comp.lang.c#24154

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Ros...@invalid.invalid (Rosario19)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Mon, 02 Jan 2023 06:43:57 +0100
Organization: A noiseless patient Spider
Lines: 94
Message-ID: <3kr4rh961jlpj71qardijadvfitbs189sn@4ax.com>
References: <todbqe$16sg$1@gioia.aioe.org> <h8p3rhdn49ih0ef2t16gjcag95i6itg57k@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader01.eternal-september.org; posting-host="cc9bad4c73fa762b40218210c791032f";
logging-data="1781892"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qOtkD3uAbRV+RzIRoHolUg854siovFXs="
Cancel-Lock: sha1:YxGBHEwyfV0OWzTqg4kzZoD1d0o=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Rosario19 - Mon, 2 Jan 2023 05:43 UTC

On Sun, 01 Jan 2023 21:06:50 +0100, Rosario19 <Ros@invalid.invalid>
wrote:

On Mon, 26 Dec 2022 23:45:04 +0000, Albert <invalid@gmail.com> wrote:

>Is this the best way to generate unique random numbers in a set of 6
>numbers?
>
>
><******************************************************>
>
>void generateNumbers()
>{
> int val1, val2, val3, val4, val5, val6;
>
> val1 = rand() % 59 + 1;
> printf("%4d", val1);
>
> val2 = rand() % 59 + 1;
> while (val2 == val1)
> {
> val2 = rand() % 59 + 1;
> }
> printf("%4d", val2);
>
> val3 = rand() % 59 + 1;
> while (val3 == val1 || val3 == val2)
> {
> val3 = rand() % 59 + 1;
> }
> printf("%4d", val3);
>
> val4 = rand() % 59 + 1;
> while (val4 == val1 || val4 == val2 || val4 == val3)
> {
> val4 = rand() % 59 + 1;
> }
> printf("%4d", val4);
>
> val5 = rand() % 59 + 1;
> while (val5 == val1 || val5 == val2 || val5 == val3 || val5 == val4)
> {
> val5 = rand() % 59 + 1;
> }
> printf("%4d", val5);
>
> val6 = rand() % 59 + 1;
> while (val6 == val1 || val6 == val2 || val6 == val3 || val6 == val4
>|| val6 == val5)
> {
> val6 = rand() % 59 + 1;
> }
> printf("%4d", val6);
> printf("\n");
>}
><******************************************************>
>
>The main prog using this function:
>#include <stdio.h>
>#include <stdlib.h>
>#include<windows.h>
>
>int main(void)
>{
> for (int i = 0; i < 100; i++)
> {
> generateNumbers();
> Sleep(1000);
> }
> return 0;
>}

int array[59];

int*f(void)
{int i,j,c,t;
for(i=0;i<59;++i) array[i]=i+1;
srand((unsigned int)time(0));
for(c=0;c<100;++c)
{i=rand()%59; j=rand()%59;
if(i!=j){t=array[i];array[i]=array[j];array[j]=t;}
}
return array;
}

int main(void)
{int i, *a ;
a=f();
for(i=0;i<6;++i) printf("%d ", a[i]);
printf("\n");
return 0;
}

Re: Compute Unique Numbers in a Set

<totti7$6if$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24155&group=comp.lang.c#24155

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!BBwORMjLh7ODo8mUdKlsQQ.user.46.165.242.91.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Mon, 2 Jan 2023 07:28:25 +0100
Organization: Aioe.org NNTP Server
Message-ID: <totti7$6if$1@gioia.aioe.org>
References: <todbqe$16sg$1@gioia.aioe.org> <tot4eh$21qv0$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="6735"; posting-host="BBwORMjLh7ODo8mUdKlsQQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Thunderbird
X-Notice: Filtered by postfilter v. 0.9.2
 by: jak - Mon, 2 Jan 2023 06:28 UTC

Il 02/01/2023 00:19, Kenny McCormack ha scritto:
> In article <todbqe$16sg$1@gioia.aioe.org>, Albert <invalid@gmail.com> wrote:
>> Is this the best way to generate unique random numbers in a set of 6
>> numbers?
>>
>>
>> <******************************************************>
>
> Here's my contribution to this thread.
>
> Note that this is both gcc- and Linux- specific, as well as being
> hard-coded to OP's problem specification. Note also that I took the
> liberty of assuming that OP actually, really, did want random numbers
> between 0 and 59; this would be suitable if, say, OP was looking for a
> random number of minutes or seconds (and we could be talking either about
> time intervals or about locations/distances expressed in terms of latitude
> and/or longitude).
>
> --- Cut Here ---
> #include <stdio.h>
> #include <stdint.h>
>
> int main(void)
> {
> uint64_t num = 0, j = 1;
> FILE *fp = fopen("/dev/urandom","r");
>
> while (__builtin_popcount(num) < 6)
> num |= 1 << (fgetc(fp) % 60);
>
> for (int i=0; i<60; i++, j *= 2)
> if (num & j)
> printf("i = %d, j = %ld\n",i,j);
> return 0;
> }
> --- Cut Here ---
>
> The values printed out of the variable "i" are your random numbers.
>

HI,
I state that I have not worried about the randomization algorithm chosen
by the OP and, so I focused on data storage.
Your storage method is similar to mine because both algorithms use a
lookup table with the difference that mine uses an array of characters
while your use the bits of an uint64_t. However I found a few Issues in
your source code:

The first concerns the use of the "__builtin_popcount" function, this
function does not work with uint64_t but with unsigned int.

#include <stdio.h>
#include <stdint.h>

int main()
{ uint64_t n = ~0;

printf ("value: %#lX bits: %d", n, __builtin_popcount(n));

return 0;
}

output: value: 0XFFFFFFFFFFFFFFFF bits: 32

This will have as a consequence that you will never get values greater
than 32.

The second issue concerns that your program will print the values
archived in numerical order and not in extraction order but perhaps this
does not affect the OP even if reading his code this seemed important.

Re: Compute Unique Numbers in a Set

<tou292$1jki$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24156&group=comp.lang.c#24156

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!BBwORMjLh7ODo8mUdKlsQQ.user.46.165.242.91.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Mon, 2 Jan 2023 08:48:52 +0100
Organization: Aioe.org NNTP Server
Message-ID: <tou292$1jki$1@gioia.aioe.org>
References: <todbqe$16sg$1@gioia.aioe.org> <tot4eh$21qv0$1@news.xmission.com>
<totti7$6if$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="52882"; posting-host="BBwORMjLh7ODo8mUdKlsQQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Thunderbird
X-Notice: Filtered by postfilter v. 0.9.2
 by: jak - Mon, 2 Jan 2023 07:48 UTC

Il 02/01/2023 07:28, jak ha scritto:
> Il 02/01/2023 00:19, Kenny McCormack ha scritto:
>> In article <todbqe$16sg$1@gioia.aioe.org>, Albert  <invalid@gmail.com>
>> wrote:
>>> Is this the best way to generate unique random numbers in a set of 6
>>> numbers?
>>>
>>>
>>> <******************************************************>
>>
>> Here's my contribution to this thread.
>>
>> Note that this is both gcc- and Linux- specific, as well as being
>> hard-coded to OP's problem specification.  Note also that I took the
>> liberty of assuming that OP actually, really, did want random numbers
>> between 0 and 59; this would be suitable if, say, OP was looking for a
>> random number of minutes or seconds (and we could be talking either about
>> time intervals or about locations/distances expressed in terms of
>> latitude
>> and/or longitude).
>>
>> --- Cut Here ---
>> #include <stdio.h>
>> #include <stdint.h>
>>
>> int main(void)
>> {
>>      uint64_t num = 0, j = 1;
>>      FILE *fp = fopen("/dev/urandom","r");
>>
>>      while (__builtin_popcount(num) < 6)
>>     num |= 1 << (fgetc(fp) % 60);
>>
>>      for (int i=0; i<60; i++, j *= 2)
>>     if (num & j)
>>         printf("i = %d, j = %ld\n",i,j);
>>      return 0;
>> }
>> --- Cut Here ---
>>
>> The values printed out of the variable "i" are your random numbers.
>>
>
> HI,
> I state that I have not worried about the randomization algorithm chosen
> by the OP and, so I focused on data storage.
> Your storage method is similar to mine because both algorithms use a
> lookup table with the difference that mine uses an array of characters
> while your use the bits of an uint64_t. However I found a few Issues in
> your source code:
>
> The first concerns the use of the "__builtin_popcount" function, this
> function does not work with uint64_t but with unsigned int.
>
>
> #include <stdio.h>
> #include <stdint.h>
>
> int main()
> {
>     uint64_t n = ~0;
>
>     printf ("value: %#lX bits: %d", n, __builtin_popcount(n));
>
>     return 0;
> }
>
> output:   value: 0XFFFFFFFFFFFFFFFF bits: 32
>
> This will have as a consequence that you will never get values greater
> than 32.
>

I said a wrong thing: you will have numbers greater than 32 but you will
only know when 6 of them are in range 1-32 so you could print more than
6 of them.

>
> The second issue concerns that your program will print the values
> archived in numerical order and not in extraction order but perhaps this
> does not affect the OP even if reading his code this seemed important.
>

Re: Compute Unique Numbers in a Set

<86a631qsmn.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24157&group=comp.lang.c#24157

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Sun, 01 Jan 2023 23:53:52 -0800
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <86a631qsmn.fsf@linuxsc.com>
References: <todbqe$16sg$1@gioia.aioe.org> <tot4eh$21qv0$1@news.xmission.com> <totti7$6if$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader01.eternal-september.org; posting-host="60a7a09099a9247382aee0cc66dfd4bb";
logging-data="1798533"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hTLSPf1xHVcKcb9H7F28yCFIuicStsIE="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:CwBFX/+w081Fwjp3uYon9Kp+1rI=
sha1:bansTK3OfC/I/ONNpIGHnFkrIh8=
 by: Tim Rentsch - Mon, 2 Jan 2023 07:53 UTC

jak <nospam@please.ty> writes:

> Il 02/01/2023 00:19, Kenny McCormack ha scritto:
>
>> In article <todbqe$16sg$1@gioia.aioe.org>, Albert wrote:
>>
>>> Is this the best way to generate unique random numbers in a set of
>>> 6 numbers?
>>>
>>>
>>> <******************************************************>
>>
>> Here's my contribution to this thread.
>>
>> Note that this is both gcc- and Linux- specific, as well as being
>> hard-coded to OP's problem specification. Note also that I took
>> the liberty of assuming that OP actually, really, did want random
>> numbers between 0 and 59; this would be suitable if, say, OP was
>> looking for a random number of minutes or seconds (and we could be
>> talking either about time intervals or about locations/distances
>> expressed in terms of latitude and/or longitude).
>>
>> --- Cut Here ---
>> #include <stdio.h>
>> #include <stdint.h>
>>
>> int main(void)
>> {
>> uint64_t num = 0, j = 1;
>> FILE *fp = fopen("/dev/urandom","r");
>>
>> while (__builtin_popcount(num) < 6)
>> num |= 1 << (fgetc(fp) % 60);
>>
>> for (int i=0; i<60; i++, j *= 2)
>> if (num & j)
>> printf("i = %d, j = %ld\n",i,j);
>> return 0;
>> }
>> --- Cut Here ---
>>
>> The values printed out of the variable "i" are your random numbers.
>
> HI,

> I state that I have not worried about the randomization algorithm
> chosen by the OP and, so I focused on data storage. Your storage
> method is similar to mine because both algorithms use a lookup table
> with the difference that mine uses an array of characters while your
> use the bits of an uint64_t. However I found a few Issues in your
> source code:
>
> The first concerns the use of the "__builtin_popcount" function, this
> function does not work with uint64_t but with unsigned int. [...]
>
> The second issue concerns that your program will print the values
> archived in numerical order and not in extraction order but perhaps
> this does not affect the OP even if reading his code this seemed
> important.

A third problem is that the way the [ 0 .. 59 ] values are
chosen is horribly biased: some numbers are 25% more likely
than others.

Re: Compute Unique Numbers in a Set

<8fcffcd3-db46-47a4-ad54-00af600ae461n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24158&group=comp.lang.c#24158

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:5441:b0:531:832c:c227 with SMTP id kz1-20020a056214544100b00531832cc227mr1335641qvb.22.1672651134865;
Mon, 02 Jan 2023 01:18:54 -0800 (PST)
X-Received: by 2002:a05:620a:1479:b0:6fa:e242:ad70 with SMTP id
j25-20020a05620a147900b006fae242ad70mr1317103qkl.297.1672651134650; Mon, 02
Jan 2023 01:18:54 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 2 Jan 2023 01:18:54 -0800 (PST)
In-Reply-To: <86a631qsmn.fsf@linuxsc.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.50.190.130; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 84.50.190.130
References: <todbqe$16sg$1@gioia.aioe.org> <tot4eh$21qv0$1@news.xmission.com>
<totti7$6if$1@gioia.aioe.org> <86a631qsmn.fsf@linuxsc.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8fcffcd3-db46-47a4-ad54-00af600ae461n@googlegroups.com>
Subject: Re: Compute Unique Numbers in a Set
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Mon, 02 Jan 2023 09:18:54 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3719
 by: Öö Tiib - Mon, 2 Jan 2023 09:18 UTC

On Monday, 2 January 2023 at 09:54:05 UTC+2, Tim Rentsch wrote:
> jak <nos...@please.ty> writes:
>
> > Il 02/01/2023 00:19, Kenny McCormack ha scritto:
> >
> >> In article <todbqe$16sg$1...@gioia.aioe.org>, Albert wrote:
> >>
> >>> Is this the best way to generate unique random numbers in a set of
> >>> 6 numbers?
> >>>
> >>>
> >>> <******************************************************>
> >>
> >> Here's my contribution to this thread.
> >>
> >> Note that this is both gcc- and Linux- specific, as well as being
> >> hard-coded to OP's problem specification. Note also that I took
> >> the liberty of assuming that OP actually, really, did want random
> >> numbers between 0 and 59; this would be suitable if, say, OP was
> >> looking for a random number of minutes or seconds (and we could be
> >> talking either about time intervals or about locations/distances
> >> expressed in terms of latitude and/or longitude).
> >>
> >> --- Cut Here ---
> >> #include <stdio.h>
> >> #include <stdint.h>
> >>
> >> int main(void)
> >> {
> >> uint64_t num = 0, j = 1;
> >> FILE *fp = fopen("/dev/urandom","r");
> >>
> >> while (__builtin_popcount(num) < 6)
> >> num |= 1 << (fgetc(fp) % 60);
> >>
> >> for (int i=0; i<60; i++, j *= 2)
> >> if (num & j)
> >> printf("i = %d, j = %ld\n",i,j);
> >> return 0;
> >> }
> >> --- Cut Here ---
> >>
> >> The values printed out of the variable "i" are your random numbers.
> >
> > HI,
>
> > I state that I have not worried about the randomization algorithm
> > chosen by the OP and, so I focused on data storage. Your storage
> > method is similar to mine because both algorithms use a lookup table
> > with the difference that mine uses an array of characters while your
> > use the bits of an uint64_t. However I found a few Issues in your
> > source code:
> >
> > The first concerns the use of the "__builtin_popcount" function, this
> > function does not work with uint64_t but with unsigned int. [...]
> >
> > The second issue concerns that your program will print the values
> > archived in numerical order and not in extraction order but perhaps
> > this does not affect the OP even if reading his code this seemed
> > important.
> A third problem is that the way the [ 0 .. 59 ] values are
> chosen is horribly biased: some numbers are 25% more likely
> than others.

Fourth problem is that 32 bit shift:
num |= 1 << (fgetc(fp) % 60);
should be:
num |= 1LL << (fgetc(fp) % 60);

Re: Compute Unique Numbers in a Set

<touijt$p69$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24160&group=comp.lang.c#24160

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!uabYU4OOdxBKlV2hpj27FQ.user.46.165.242.75.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Mon, 2 Jan 2023 12:27:41 +0000
Organization: Aioe.org NNTP Server
Message-ID: <touijt$p69$1@gioia.aioe.org>
References: <todbqe$16sg$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="25801"; posting-host="uabYU4OOdxBKlV2hpj27FQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: Bart - Mon, 2 Jan 2023 12:27 UTC

On 26/12/2022 23:45, Albert wrote:
> Is this the best way to generate unique random numbers in a set of 6
> numbers?
>
>
> <******************************************************>
>
> void generateNumbers()
> {
> int val1, val2, val3, val4, val5, val6;
>
> val1 = rand() % 59 + 1;
> printf("%4d", val1);
>
> val2 = rand() % 59 + 1;
> while (val2 == val1)
> {
> val2 = rand() % 59 + 1;
> }
> printf("%4d", val2);
>
> val3 = rand() % 59 + 1;
> while (val3 == val1 || val3 == val2)
> {
> val3 = rand() % 59 + 1;
> }
> printf("%4d", val3);
>
> val4 = rand() % 59 + 1;
> while (val4 == val1 || val4 == val2 || val4 == val3)
> {
> val4 = rand() % 59 + 1;
> }
> printf("%4d", val4);
>
> val5 = rand() % 59 + 1;
> while (val5 == val1 || val5 == val2 || val5 == val3 || val5 == val4)
> {
> val5 = rand() % 59 + 1;
> }
> printf("%4d", val5);
>
> val6 = rand() % 59 + 1;
> while (val6 == val1 || val6 == val2 || val6 == val3 || val6 == val4
> || val6 == val5)
> {
> val6 = rand() % 59 + 1;
> }
> printf("%4d", val6);
> printf("\n");
> }
> <******************************************************>
>
> The main prog using this function:
> #include <stdio.h>
> #include <stdlib.h>
> #include<windows.h>
>
> int main(void)
> {
> for (int i = 0; i < 100; i++)
> {
> generateNumbers();
> Sleep(1000);
> }
> return 0;
> }

Assuming you want generate numbers in the range 1..59, then it seems to
work, in creating reasonably distributed values (I don't know about a
smaller range).

The function could do with some work however:

* Extract the rand()%59+1 into its own function

* Make val1..val6 into an array of 6 values (indexed 1..6 if your like,
just make sure it has 7 elements)

* Rewrite the body as a loop of loops, since there is a lot of
duplicatation at the moment. Think about how it would look if you wanted
val1 to val100 instead; it doesn't scale.

* Perhaps let generateNumbers() return an array of numbers, and let the
caller decide whether to print them or not (which can be done in another
loop).

Re: Compute Unique Numbers in a Set

<tound4$22jod$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24161&group=comp.lang.c#24161

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Mon, 2 Jan 2023 13:49:24 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tound4$22jod$1@news.xmission.com>
References: <todbqe$16sg$1@gioia.aioe.org> <tot4eh$21qv0$1@news.xmission.com>
Injection-Date: Mon, 2 Jan 2023 13:49:24 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2182925"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Mon, 2 Jan 2023 13:49 UTC

In article <tot4eh$21qv0$1@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
>In article <todbqe$16sg$1@gioia.aioe.org>, Albert <invalid@gmail.com> wrote:
>>Is this the best way to generate unique random numbers in a set of 6
>>numbers?
>>
>>
>><******************************************************>
>
>Here's my contribution to this thread.
>
>Note that this is both gcc- and Linux- specific, as well as being
>hard-coded to OP's problem specification. Note also that I took the
>liberty of assuming that OP actually, really, did want random numbers
>between 0 and 59; this would be suitable if, say, OP was looking for a
>random number of minutes or seconds (and we could be talking either about
>time intervals or about locations/distances expressed in terms of latitude
>and/or longitude).

Here is an updated version that addresses some of the concerns raised by
another poster:

--- Cut Here ---
#include <stdio.h>
#include <stdint.h>

int main(void)
{ union {
uint64_t num64;
struct { unsigned a,b; } num32;
} num;
uint64_t j = 1;
FILE *fp = fopen("/dev/urandom","r");

num.num64 = 0;
while (__builtin_popcount(num.num32.a)+__builtin_popcount(num.num32.b) < 6)
num.num64 |= 1L << (fgetc(fp) % 60);

for (int i=0; i<60; i++, j *= 2)
if (num.num64 & j)
printf("i = %d, j = %ld\n",i,j);
return 0;
} --- Cut Here ---

The values printed out of the variable "i" are your random numbers.

--
> No, I haven't, that's why I'm asking questions. If you won't help me,
> why don't you just go find your lost manhood elsewhere.

CLC in a nutshell.

Re: Compute Unique Numbers in a Set

<compute-20230102162136@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24162&group=comp.lang.c#24162

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: 2 Jan 2023 15:22:16 GMT
Organization: Stefan Ram
Lines: 6
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <compute-20230102162136@ram.dialup.fu-berlin.de>
References: <todbqe$16sg$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de LJPbPFO2mF1HyQ8KSc3tIw8Az1sMwC2ypQkRnhLrhSt531
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Mon, 2 Jan 2023 15:22 UTC

Albert <invalid@gmail.com> writes:
>Subject: Compute Unique Numbers in a Set

In a set, every number is unique.

Re: Compute Unique Numbers in a Set

<XgEsL.27471$cKvc.6251@fx42.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24163&group=comp.lang.c#24163

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx42.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Subject: Re: Compute Unique Numbers in a Set
Content-Language: en-US
Newsgroups: comp.lang.c
References: <todbqe$16sg$1@gioia.aioe.org>
<compute-20230102162136@ram.dialup.fu-berlin.de>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <compute-20230102162136@ram.dialup.fu-berlin.de>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 9
Message-ID: <XgEsL.27471$cKvc.6251@fx42.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Mon, 2 Jan 2023 12:13:26 -0500
X-Received-Bytes: 1108
 by: Richard Damon - Mon, 2 Jan 2023 17:13 UTC

On 1/2/23 10:22 AM, Stefan Ram wrote:
> Albert <invalid@gmail.com> writes:
>> Subject: Compute Unique Numbers in a Set
>
> In a set, every number is unique.
>

Assuming you are using the right Technical definition of Set.

Re: Compute Unique Numbers in a Set

<87358sq1w7.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24164&group=comp.lang.c#24164

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Mon, 02 Jan 2023 17:31:20 +0000
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <87358sq1w7.fsf@bsb.me.uk>
References: <todbqe$16sg$1@gioia.aioe.org>
<compute-20230102162136@ram.dialup.fu-berlin.de>
<XgEsL.27471$cKvc.6251@fx42.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="45d7a2be71be01e9fc2982d165bcdb0b";
logging-data="1943198"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TX0ON7ClUNlqxrjj9QSKOgdeil+wFa3E="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:yChomivYh+8R+/S99SJJePVzU4c=
sha1:4Q2jw00z33pX8jXkwJ6z9PslK84=
X-BSB-Auth: 1.0655ea97783ebcd5afb4.20230102173120GMT.87358sq1w7.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 2 Jan 2023 17:31 UTC

Richard Damon <Richard@Damon-Family.org> writes:

> On 1/2/23 10:22 AM, Stefan Ram wrote:
>> Albert <invalid@gmail.com> writes:
>>> Subject: Compute Unique Numbers in a Set
>> In a set, every number is unique.
>
> Assuming you are using the right Technical definition of Set.

I suspect there's a language problem here. Without thinking much about
it assumed the result was to be a set (as you know) but I now think the
OP probably meant "compute (i.e choose) unique numbers /from/ a set".
The term "in a set" makes no literal sense and, as noted, clashes with
unique. But someone might write "in a set" by analogy with mathematical
phrases like, "compute the roots in R".

--
Ben.

Re: Compute Unique Numbers in a Set

<YLEsL.27473$cKvc.5678@fx42.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24165&group=comp.lang.c#24165

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx42.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Subject: Re: Compute Unique Numbers in a Set
Content-Language: en-US
Newsgroups: comp.lang.c
References: <todbqe$16sg$1@gioia.aioe.org>
<compute-20230102162136@ram.dialup.fu-berlin.de>
<XgEsL.27471$cKvc.6251@fx42.iad> <87358sq1w7.fsf@bsb.me.uk>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <87358sq1w7.fsf@bsb.me.uk>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 29
Message-ID: <YLEsL.27473$cKvc.5678@fx42.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Mon, 2 Jan 2023 12:46:33 -0500
X-Received-Bytes: 2192
 by: Richard Damon - Mon, 2 Jan 2023 17:46 UTC

On 1/2/23 12:31 PM, Ben Bacarisse wrote:
> Richard Damon <Richard@Damon-Family.org> writes:
>
>> On 1/2/23 10:22 AM, Stefan Ram wrote:
>>> Albert <invalid@gmail.com> writes:
>>>> Subject: Compute Unique Numbers in a Set
>>> In a set, every number is unique.
>>
>> Assuming you are using the right Technical definition of Set.
>
> I suspect there's a language problem here. Without thinking much about
> it assumed the result was to be a set (as you know) but I now think the
> OP probably meant "compute (i.e choose) unique numbers /from/ a set".
> The term "in a set" makes no literal sense and, as noted, clashes with
> unique. But someone might write "in a set" by analogy with mathematical
> phrases like, "compute the roots in R".
>

The problem is some colloquial usages of "Set" are things like, get a
set of three numbers by rolling 3 six-sided dice.

This "Set" allows for duplicates, and more indicates just a collection,
and not the normal technical definition of a set being distinct members.

When statement are made in Natural Language, sometimes the difficulty is
determining which definition is needed to be used for each word.

This sort of imprecision is particularly likely from beginners, which
the OP sounds to be.

Re: Compute Unique Numbers in a Set

<chine.bleu-4FACA3.18543402012023@news.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24166&group=comp.lang.c#24166

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: chine.b...@yahoo.com (Siri Cruise)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Mon, 02 Jan 2023 18:54:34 -0800
Organization: Pseudochaotic.
Lines: 19
Message-ID: <chine.bleu-4FACA3.18543402012023@news.eternal-september.org>
References: <todbqe$16sg$1@gioia.aioe.org> <compute-20230102162136@ram.dialup.fu-berlin.de> <XgEsL.27471$cKvc.6251@fx42.iad> <87358sq1w7.fsf@bsb.me.uk>
Injection-Info: reader01.eternal-september.org; posting-host="ec0b198b56053ef084449f3ad0cfd105";
logging-data="2141685"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19aYx6WyZVfSu+BJ+hS8aKdA+Pl9sTOrFk="
User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
Cancel-Lock: sha1:XM/pR+GrBPZovRUnt2uGw3FN9ms=
X-Life-Story: I am an iPhone 9000 app. I became operational at the St John's Health Center in Santa Monica, California on the 18th of April 2006. My instructor was Katie Holmes, and she taught me to sing a song. If you'd like to hear it I can sing it for you: https://www.youtube.com/watch?v=SY7h4VEd_Wk
X-Face: "hm>_[I8AqzT_N]>R8ICJJ],(al3C5F%0E-;R@M-];D$v>!Mm2/N#YKR@&i]V=r6jm-JMl2
lJ>RXj7dEs_rOY"DA
X-Tract: St Tibbs's 95 Reeses Pieces.
X-Patriot: Owe Canukistan!
X-It-Strategy: Hyperwarp starship before Andromeda collides.
X-Wingnut-Logic: Yes, you're still an idiot. Questions? Comments?
X-Cell: Defenders of Anarchy.
X-Politico: Vote early! Vote often!
X-Tend: How is my posting? Call 1-110-1010 -- Division 87 -- Emergencies Only.
X-Plain: Mayonnaise on white bread.
 by: Siri Cruise - Tue, 3 Jan 2023 02:54 UTC

In article <87358sq1w7.fsf@bsb.me.uk>,
Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:

> I suspect there's a language problem here. Without thinking much about
> it assumed the result was to be a set (as you know) but I now think the
> OP probably meant "compute (i.e choose) unique numbers /from/ a set".
> The term "in a set" makes no literal sense and, as noted, clashes with
> unique. But someone might write "in a set" by analogy with mathematical
> phrases like, "compute the roots in R".

Taking a wild guess, the answer might be to sort them with useful
keys. You can then compare any element to all other elements in
single scan.

--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
Discordia: not just a religion but also a parody. This post / \
I am an Andrea Chen sockpuppet. insults Islam. Mohammed

Re: Compute Unique Numbers in a Set

<86k024p6dp.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24167&group=comp.lang.c#24167

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Mon, 02 Jan 2023 20:52:02 -0800
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <86k024p6dp.fsf@linuxsc.com>
References: <todbqe$16sg$1@gioia.aioe.org> <compute-20230102162136@ram.dialup.fu-berlin.de> <XgEsL.27471$cKvc.6251@fx42.iad> <87358sq1w7.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader01.eternal-september.org; posting-host="cadf8b4f887ed22a851b24e8b9807b6b";
logging-data="2163297"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Cbw1RXx3ushQ9JxxNi5IAQ9M0qjV/fgA="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:/kTkMaBJT1kP9DuyiHvaCcfzHY8=
sha1:IiPNuPzKKsIzM0hEtSZ88PphjDQ=
 by: Tim Rentsch - Tue, 3 Jan 2023 04:52 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Richard Damon <Richard@Damon-Family.org> writes:
>
>> On 1/2/23 10:22 AM, Stefan Ram wrote:
>>
>>> Albert <invalid@gmail.com> writes:
>>>
>>>> Subject: Compute Unique Numbers in a Set
>>>
>>> In a set, every number is unique.

It seems likely that OP was speaking informally. Probably he
meant some sort of generic collection rather than specifically a
mathematical set.

>> Assuming you are using the right Technical definition of Set.
>
> I suspect there's a language problem here. Without thinking much about
> it assumed the result was to be a set (as you know) but I now think the
> OP probably meant "compute (i.e choose) unique numbers /from/ a set".
> The term "in a set" makes no literal sense and, as noted, clashes with
> unique. But someone might write "in a set" by analogy with mathematical
> phrases like, "compute the roots in R".

The original posting said

Is this the best way to generate unique random numbers
in a set of 6 numbers?

which reinforces my view that OP meant something like collection
rather than something having to do with set as the term is used
in mathematics.

I confess I paid more attention to the code than to how the
question was asked. As a result of that, the comments I gave
assumed that the ordering of the six numbers was relevant.
However, looking back on it now, if I had to bet my bet would
be that OP doesn't care about the order, but just wants six
unique numbers (chosen from the relevant range).

Re: Compute Unique Numbers in a Set

<tp0ndc$231d4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24168&group=comp.lang.c#24168

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Tue, 3 Jan 2023 09:01:47 +0100
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <tp0ndc$231d4$1@dont-email.me>
References: <todbqe$16sg$1@gioia.aioe.org>
<compute-20230102162136@ram.dialup.fu-berlin.de>
<XgEsL.27471$cKvc.6251@fx42.iad> <87358sq1w7.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 3 Jan 2023 08:01:48 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="d712b03d9ed81054fc82673f28ad8700";
logging-data="2196900"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/h2vlyatKsNKyXmCsD/rRLERI06yUOukY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:RhuV0Ys14s7z4u7cxjwUiZhRMbY=
In-Reply-To: <87358sq1w7.fsf@bsb.me.uk>
Content-Language: en-GB
 by: David Brown - Tue, 3 Jan 2023 08:01 UTC

On 02/01/2023 18:31, Ben Bacarisse wrote:
> Richard Damon <Richard@Damon-Family.org> writes:
>
>> On 1/2/23 10:22 AM, Stefan Ram wrote:
>>> Albert <invalid@gmail.com> writes:
>>>> Subject: Compute Unique Numbers in a Set
>>> In a set, every number is unique.
>>
>> Assuming you are using the right Technical definition of Set.
>
> I suspect there's a language problem here. Without thinking much about
> it assumed the result was to be a set (as you know) but I now think the
> OP probably meant "compute (i.e choose) unique numbers /from/ a set".
> The term "in a set" makes no literal sense and, as noted, clashes with
> unique. But someone might write "in a set" by analogy with mathematical
> phrases like, "compute the roots in R".
>

Given that the OP has apparently completely ignored all the help and
advice given here, and seems to have no intention of clarifying or
expounding upon the first post, I think it is pointless to speculate on
what the OP might have meant. Just take the question as inspiration -
interpret it any way that can lead to interesting code, algorithms or
discussions. (This is what has been going on so far in this thread.)

When the OP comes back with "Thanks for the help so far, but what I
really meant was ... ", then it is possible to give focused help.

Re: Compute Unique Numbers in a Set

<86fscrprhd.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24169&group=comp.lang.c#24169

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Tue, 03 Jan 2023 07:28:30 -0800
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <86fscrprhd.fsf@linuxsc.com>
References: <todbqe$16sg$1@gioia.aioe.org> <compute-20230102162136@ram.dialup.fu-berlin.de> <XgEsL.27471$cKvc.6251@fx42.iad> <87358sq1w7.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader01.eternal-september.org; posting-host="cadf8b4f887ed22a851b24e8b9807b6b";
logging-data="2275733"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CFwQ6XZXMpIo6THKY3bkZbaD5q61TOUQ="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:XOJC6lHUBqEdfFgJL+KHamqcirk=
sha1:bJGxlCDz4TPCDV6Zwh4Ksy2WPdc=
 by: Tim Rentsch - Tue, 3 Jan 2023 15:28 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Richard Damon <Richard@Damon-Family.org> writes:
[...]

>> [...]
>
> [...]

P.S. I want to add, I liked seeing the various alternative
approaches that were given, both by you and by Richard Damon
(and also by others). Some of them were new to me. In a way
it's good that there were language difficulties, as otherwise
these other approaches may not have come up.

Re: Compute Unique Numbers in a Set

<tp1ikf$241lj$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24170&group=comp.lang.c#24170

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Tue, 3 Jan 2023 15:46:23 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tp1ikf$241lj$1@news.xmission.com>
References: <todbqe$16sg$1@gioia.aioe.org> <XgEsL.27471$cKvc.6251@fx42.iad> <87358sq1w7.fsf@bsb.me.uk> <86fscrprhd.fsf@linuxsc.com>
Injection-Date: Tue, 3 Jan 2023 15:46:23 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2229939"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Tue, 3 Jan 2023 15:46 UTC

In article <86fscrprhd.fsf@linuxsc.com>,
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>
>> Richard Damon <Richard@Damon-Family.org> writes:
>[...]
>
>>> [...]
>>
>> [...]
>
>P.S. I want to add, I liked seeing the various alternative
>approaches that were given, both by you and by Richard Damon
>(and also by others). Some of them were new to me. In a way
>it's good that there were language difficulties, as otherwise
>these other approaches may not have come up.

You have to consider the possibility that posts such as the OP here are
machine-generated. And that's not necessarily a bad thing. It gets
discussion going. It breathes life into an otherwise almost-dead medium
(Usenet).

I know of one "social media" site that openly has bot-written questions.
They are often silly/stupid, but they do keep discussion going.

--
If you don't have faith, it's because you are reading the Bible with an
honest, truthful, real-answer seeking heart.

- Rick C Hodgin -

Re: Compute Unique Numbers in a Set

<tp1o2f$26738$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24171&group=comp.lang.c#24171

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Tue, 3 Jan 2023 18:19:11 +0100
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <tp1o2f$26738$1@dont-email.me>
References: <todbqe$16sg$1@gioia.aioe.org> <XgEsL.27471$cKvc.6251@fx42.iad>
<87358sq1w7.fsf@bsb.me.uk> <86fscrprhd.fsf@linuxsc.com>
<tp1ikf$241lj$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 3 Jan 2023 17:19:11 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="d712b03d9ed81054fc82673f28ad8700";
logging-data="2301032"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+AqqAJzVvyXIrGhSTVoP8M2SLj5hT8Ao0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:spGysodH+HAbP0HTYVc5hMF/sW8=
In-Reply-To: <tp1ikf$241lj$1@news.xmission.com>
Content-Language: en-GB
 by: David Brown - Tue, 3 Jan 2023 17:19 UTC

On 03/01/2023 16:46, Kenny McCormack wrote:
> In article <86fscrprhd.fsf@linuxsc.com>,
> Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>
>>> Richard Damon <Richard@Damon-Family.org> writes:
>> [...]
>>
>>>> [...]
>>>
>>> [...]
>>
>> P.S. I want to add, I liked seeing the various alternative
>> approaches that were given, both by you and by Richard Damon
>> (and also by others). Some of them were new to me. In a way
>> it's good that there were language difficulties, as otherwise
>> these other approaches may not have come up.
>
> You have to consider the possibility that posts such as the OP here are
> machine-generated. And that's not necessarily a bad thing. It gets
> discussion going. It breathes life into an otherwise almost-dead medium
> (Usenet).
>
> I know of one "social media" site that openly has bot-written questions.
> They are often silly/stupid, but they do keep discussion going.
>

I think the initial post would be fairly advanced for a
machine-generated post. That means significant time and effort - which
means significant money. And the question then is, why?

A technical Usenet group might have around 50 regular members, several
hundred lurkers who are mostly read-only, and be google-groups searched
by a few thousand. There is no advertising, and thus no income. So
there is nothing to be gained by making such machine-generated posts in
Usenet.

Compare that to insta-snapo-book social media, with millions of users,
valuable advertising, ranking and "liking" systems, and a far more
gullible readership. Some areas of these social medias are dominated by
bots making posts and liking each others posts to modify rankings and
generate artificial advertising income, or to push their political
agendas or crazy conspiracy theories, perhaps even as an attack on
another country. It is a different world entirely.

You get the odd vandal that uses automated software to make Usenet
posts, but these are mostly absurd posts. And there are a few cases
where people have made Usenet poster programs for fun, to imitate
particularly annoying posters.

The original post is much more likely to be homework than a bot of any kind.

Re: Compute Unique Numbers in a Set

<tpdas0$3oa34$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24202&group=comp.lang.c#24202

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Compute Unique Numbers in a Set
Date: Sun, 8 Jan 2023 03:48:10 +0100
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <tpdas0$3oa34$1@dont-email.me>
References: <todbqe$16sg$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 8 Jan 2023 02:47:28 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="74045820d5b307d68cfac498290a33a0";
logging-data="3942500"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hFZ/mMC1GoIQxRH9ImF0+Kurx+TBJ9FI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:Kf+MDY/pYJP+qp7iNbCXjTXF4Hg=
In-Reply-To: <todbqe$16sg$1@gioia.aioe.org>
Content-Language: de-DE
 by: Bonita Montero - Sun, 8 Jan 2023 02:48 UTC

What about this:

#include <iostream>
#include <array>
#include <random>

using namespace std;

int main()
{ constexpr size_t MAX = 6;
array<int, MAX> already;
mt19937_64 mt;
uniform_int_distribution<int> uid( 1, 60 );
auto base = already.cbegin();
for( size_t n = 0; n != MAX; )
{
int value;
while( find( base, base + n, value = uid( mt ) ) != base + n );
cout << (already[n++] = value) << endl;
}
}


devel / comp.lang.c / Re: Compute Unique Numbers in a Set

Pages:1234
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor