On Thu, 28 Jul 2022 at 05:36, Cecil Westerhof via Python-list
wrote:
>
> Roel Schroeven writes:
>
> > Cecil Westerhof via Python-list schreef op 27/07/2022 om 17:43:
> >> "Michael F. Stemper" writes:
> >>
> >> > This is orthogonal to your question, but might be of some use to you:
> >> >
> >> >
Cecil Westerhof writes:
Alan Bawden writes:
> Cecil Westerhof writes:
>
>Yes, I try to select a random element, but it has also to be removed,
>because an element should not be used more as once.
>
> Instead of using pop to do that why not something like:
>
>
Alan Bawden writes:
> Cecil Westerhof writes:
>
>Yes, I try to select a random element, but it has also to be removed,
>because an element should not be used more as once.
>
> Instead of using pop to do that why not something like:
>
> def lazy_shuffle(seq):
> """
> G
MRAB writes:
>>> When you pop an element from the last, the elements after it need to be
>>> moved down, which takes time.
>>>
>>> Try shuffling the list and then popping the now randomly-ordered
>>> elements off the end.
>> Would shuffling not be a lot more expensive? Especially because I do
>>
Roel Schroeven writes:
> Cecil Westerhof via Python-list schreef op 27/07/2022 om 17:43:
>> "Michael F. Stemper" writes:
>>
>> > This is orthogonal to your question, but might be of some use to you:
>> >
>> > The combination of using len(to_try) as an argument to randint() and
>> > saving the ou
On 27/07/2022 18:24, Cecil Westerhof via Python-list wrote:
MRAB writes:
On 27/07/2022 16:43, Cecil Westerhof via Python-list wrote:
"Michael F. Stemper" writes:
This is orthogonal to your question, but might be of some use to you:
The combination of using len(to_try) as an argument to ra
Cecil Westerhof writes:
Yes, I try to select a random element, but it has also to be removed,
because an element should not be used more as once.
Instead of using pop to do that why not something like:
def lazy_shuffle(seq):
"""
Generate the elements of the given seque
Cecil Westerhof via Python-list schreef op 27/07/2022 om 17:43:
"Michael F. Stemper" writes:
> This is orthogonal to your question, but might be of some use to you:
>
> The combination of using len(to_try) as an argument to randint() and
> saving the output to a variable named "index" suggests
MRAB writes:
> On 27/07/2022 16:43, Cecil Westerhof via Python-list wrote:
>> "Michael F. Stemper" writes:
>>
>>> This is orthogonal to your question, but might be of some use to you:
>>>
>>> The combination of using len(to_try) as an argument to randint() and
>>> saving the output to a variabl
Dennis Lee Bieber writes:
> On Wed, 27 Jul 2022 10:45:47 +0200, Cecil Westerhof
> declaimed the following:
>
>
>>What do you mean with where the python version is from?
>
> Base Python.org download, ActiveState package download, Anaconda
> package download, native OS install/extra install
> On 27 Jul 2022, at 17:09, Cecil Westerhof via Python-list
> wrote:
>
> Barry writes:
>
On 26 Jul 2022, at 16:07, Cecil Westerhof via Python-list
wrote:
>>>
>>> I need to get a random integer. At first I tried it with:
>>> from secrets import randbelow
>>> index = randbel
On 7/27/22 02:45, Cecil Westerhof via Python-list wrote:
> Barry writes:
>> What version of python and where from?
>
> That is always good information of-course.
> Debian 11.3
> 5.10.0-13-amd64
> 3.9.2
>
> What do you mean with where the python version is from?
On Windows, the platform of a la
On Wed, 27 Jul 2022 10:45:47 +0200, Cecil Westerhof
declaimed the following:
>What do you mean with where the python version is from?
Base Python.org download, ActiveState package download, Anaconda
package download, native OS install/extra install via OS repository
download (Debian/Ubu
On 27/07/2022 16:43, Cecil Westerhof via Python-list wrote:
"Michael F. Stemper" writes:
This is orthogonal to your question, but might be of some use to you:
The combination of using len(to_try) as an argument to randint() and
saving the output to a variable named "index" suggests that you m
On 26/07/2022 16.47, Cecil Westerhof wrote:
Chris Angelico writes:
On Wed, 27 Jul 2022 at 06:06, Cecil Westerhof via Python-list
wrote:
Chris Angelico writes:
On Wed, 27 Jul 2022 at 01:06, Cecil Westerhof via Python-list
wrote:
I need to get a random integer. At first I tried it with:
Dennis Lee Bieber writes:
> On Tue, 26 Jul 2022 23:47:59 +0200, Cecil Westerhof
> declaimed the following:
>
>
>>The new code:
>>from random import SystemRandom
>>system_random = SystemRandom()
>>index = system_random.randint(0, len(to_try) - 1)
>>
>>The first two statements are e
Chris Angelico writes:
> Incidentally - if you are actually trying to select a specific item,
> you may want to consider random.choice.
Yes, I try to select a random element, but it has also to be removed.
An element should be used at most once. This is the code I use:
# index = randbelow(le
Chris Angelico writes:
> On Wed, 27 Jul 2022 at 08:18, Cecil Westerhof via Python-list
> wrote:
>>
>> Chris Angelico writes:
>>
>> > On Wed, 27 Jul 2022 at 06:06, Cecil Westerhof via Python-list
>> > wrote:
>> >>
>> >> Chris Angelico writes:
>> >>
>> >> > On Wed, 27 Jul 2022 at 01:06, Cecil W
Barry writes:
>> On 26 Jul 2022, at 16:07, Cecil Westerhof via Python-list
>> wrote:
>>
>> I need to get a random integer. At first I tried it with:
>>from secrets import randbelow
>>index = randbelow(len(to_try))
>>
>> This works perfectly, but it took some time. So I thought I try:
"Michael F. Stemper" writes:
> This is orthogonal to your question, but might be of some use to you:
>
> The combination of using len(to_try) as an argument to randint() and
> saving the output to a variable named "index" suggests that you might
> be setting up to select a random element from to_
> On 26 Jul 2022, at 16:07, Cecil Westerhof via Python-list
> wrote:
>
> I need to get a random integer. At first I tried it with:
>from secrets import randbelow
>index = randbelow(len(to_try))
>
> This works perfectly, but it took some time. So I thought I try:
>from random imp
On Wed, 27 Jul 2022 at 09:28, Dennis Lee Bieber wrote:
>
> On Tue, 26 Jul 2022 16:38:38 +0200, Cecil Westerhof
> declaimed the following:
>
> >I need to get a random integer. At first I tried it with:
> >from secrets import randbelow
> >index = randbelow(len(to_try))
> >
> >This works per
On Tue, 26 Jul 2022 23:47:59 +0200, Cecil Westerhof
declaimed the following:
>The new code:
>from random import SystemRandom
>system_random = SystemRandom()
>index = system_random.randint(0, len(to_try) - 1)
>
>The first two statements are executed once.
>The last statement I thin
On Tue, 26 Jul 2022 16:38:38 +0200, Cecil Westerhof
declaimed the following:
>I need to get a random integer. At first I tried it with:
>from secrets import randbelow
>index = randbelow(len(to_try))
>
>This works perfectly, but it took some time. So I thought I try:
>from random impo
On Wed, 27 Jul 2022 at 08:18, Cecil Westerhof via Python-list
wrote:
>
> Chris Angelico writes:
>
> > On Wed, 27 Jul 2022 at 06:06, Cecil Westerhof via Python-list
> > wrote:
> >>
> >> Chris Angelico writes:
> >>
> >> > On Wed, 27 Jul 2022 at 01:06, Cecil Westerhof via Python-list
> >> > wrote
Chris Angelico writes:
> On Wed, 27 Jul 2022 at 06:06, Cecil Westerhof via Python-list
> wrote:
>>
>> Chris Angelico writes:
>>
>> > On Wed, 27 Jul 2022 at 01:06, Cecil Westerhof via Python-list
>> > wrote:
>> >>
>> >> I need to get a random integer. At first I tried it with:
>> >> from se
On Wed, 27 Jul 2022 at 06:06, Cecil Westerhof via Python-list
wrote:
>
> Chris Angelico writes:
>
> > On Wed, 27 Jul 2022 at 01:06, Cecil Westerhof via Python-list
> > wrote:
> >>
> >> I need to get a random integer. At first I tried it with:
> >> from secrets import randbelow
> >> index
Chris Angelico writes:
> On Wed, 27 Jul 2022 at 01:06, Cecil Westerhof via Python-list
> wrote:
>>
>> I need to get a random integer. At first I tried it with:
>> from secrets import randbelow
>> index = randbelow(len(to_try))
>>
>> This works perfectly, but it took some time. So I thoug
On Wed, 27 Jul 2022 at 01:06, Cecil Westerhof via Python-list
wrote:
>
> I need to get a random integer. At first I tried it with:
> from secrets import randbelow
> index = randbelow(len(to_try))
>
> This works perfectly, but it took some time. So I thought I try:
> from random import
Absolutely. The task (“generate a random number”) is ill-defined.
Want a fast random number? Use 552015933 (I just retrieved it from random.org).
Want a true random number, use random.org API. (https://api.random.org/pricing).
Something in between, follow approaches Stefan suggests.
—
Gerard
I need to get a random integer. At first I tried it with:
from secrets import randbelow
index = randbelow(len(to_try))
This works perfectly, but it took some time. So I thought I try:
from random import SystemRandom
index = SystemRandom().randint(0, len(to_try) - 1)
A first indic
31 matches
Mail list logo