[issue44400] Propose random.randbool()

2021-06-13 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> I would like to get opinions from Raymond and then 
> proceed with this issue.

I concur with Steven and Serhiy and don't think this should be added.

--
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44400] Propose random.randbool()

2021-06-12 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

As for randbool() I concur with Steven. It is too trivial and in most case you 
do not even need to call bool().

Alternate methods:

choice((False, True))
random() < 0.5

They are less efficient than getrandbits(1), but can be easily extended to 
non-binary output or non-uniform distribution.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44400] Propose random.randbool()

2021-06-12 Thread Dong-hee Na


Dong-hee Na  added the comment:

s / from other core-devs / from core-devs

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44400] Propose random.randbool()

2021-06-12 Thread Dong-hee Na


Dong-hee Na  added the comment:

To explain my thought,

> Not every one line expression needs to be a function in a library. 
> `bool(getrandbits(1))` is self-explanatory enough,

Yeah, I agree with the point of view, it might be enough.

But considering the popularity of the Python language and there is a lot of new 
people who enter the programming world with Python for their own purpose so 
there are a lot of people who are not familiar with the concept of bits.
So I thought that the random module can become more friendly for those people.

And for example, Java/Scala already provides those high-level APIs (and there 
is a similar proposal at Go also: https://github.com/golang/go/issues/23804). 
but it does not mean that Python should provide the same APIs. And I know that 
we also have to consider the maintenance cost and the principle of library 
scope.

Anyway, this is the reason I proposed this feature and I want to hear the 
opinion from other core-devs :)

please let me know if I miss something or historical issue.
Enjoy your weekend.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44400] Propose random.randbool()

2021-06-12 Thread Mark Dickinson


Change by Mark Dickinson :


--
nosy: +mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44400] Propose random.randbool()

2021-06-12 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

It is difficult to deprecate getrandbits() because it is one of two base 
methods. All Random methods call either getrandbits() or randome(). Overriding 
them is a way to make a new random generator.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44400] Propose random.randbool()

2021-06-11 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Not every one line expression needs to be a function in a library. 
`bool(getrandbits(1))` is self-explanatory enough, and it is doubtful that any 
implementation would be faster.

Using getrandbits(1) to return 0 or 1 is fine; if you need a bool, call bool on 
the result.

Aside: the name getrandbits is a bit sad, there's no setrandbits and we don't 
name the other random functions with a leading "get" prefix:

getrandint(1, 6)


Raymond, would you consider providing an alias randbits and depreciating the 
getrandbits name? We don't have to remove it, just document it as depreciated 
to be removed in Python 5000 :-)

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44400] Propose random.randbool()

2021-06-11 Thread Dong-hee Na


New submission from Dong-hee Na :

I noticed that the random library does not provide `random.randbool()`.
Generating bool value is quite common in the use-case when we generated faked 
data
(unittest, machine learning training, etc)

Somebody can say write your own library but it's too common use-case and in 
physically some isolated environments is hard to use 3rd party library.

Since the bool value is the built-in type of python, I think that is very 
useful when we provide this function.

I would like to get opinions from Raymond and then proceed with this issue.

Here is the candidate implementation:

def randbool():
return bool(getrandbits(1))

--
components: Library (Lib)
messages: 395671
nosy: corona10, rhettinger
priority: normal
severity: normal
status: open
title: Propose random.randbool()
type: enhancement
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com