Hey Steven,

I think there is a way to map x <- [1; + inf] to y <- [0;1] by putting y =
1/x

But i think there is another issue to consider :
for example if we want to sort :

random.choice(['a', 'b', 'c'], random=lambda: random.paretovariate(1.75)),
we should have a mapping
between the elements of the list (here :a,b,c) to [0, 1] and the reverser
mapping, having this mapping underline
that we have a notion of order and distance, "measurement" between the
elements, and it is not trivial to always
have a notion of "order" or "distance" between the elements we manipulate,
but it could be fun
to have this possibility.

What do you think ?

Thank you !

Best regards,

-- 
Hamza









Le dim. 18 août 2019 à 11:56, Steven D'Aprano <st...@pearwood.info> a
écrit :

> On Sat, Aug 17, 2019 at 09:02:54AM +0200, Patryk Gałczyński wrote:
> > Hi!
> >
> > Recently I encountered a situation when I needed to pick a random
> > population sample but with specific distribution function -
> paretovariate in
> > this particular case.
>
> Let me see if I understand... you have a paretovariate distribution, and
> you want to generate a sample of values from that distribution? Or
> another way of putting it, you want to generate random numbers from that
> distribution?
>
> Use the random.paretovariate() function (which I see you know about).
> There's no need for random.choice or other methods to be involved.
>
> That might not be what you *want*, but that is what you seem to be
> describing.
>
>
> > After poking around in the random module I found out
> > that none of the so-called "sequence methods" methods support custom
> random
> > function except for random.shuffle
>
>
> > I would like to propose a new optional keyword argument for all these
> sequence
> > methods (choice, sample, choices) that will - similarly to how shuffle
> does
> > - take a zero-argument random distribution function of the users choice.
> > Because it should be a zero-argument function, it would most likely
> require
> > to pass "configured" distribution function with lambda. I would see it
> > being used like this:
> >
> > ```python
> > import random
> > random.choice([1, 2, 3], random=lambda: random.paretovariate(1.75))
> > ```
> The docs for shuffle say that:
>
>     The optional argument random is a 0-argument function returning
>     a random float in [0.0, 1.0); by default, this is the function
>     random().
>
> but random.paretovariate returns a float between [1.0, ∞). By
> definition, every value it produces is out of range, and there's no way
> of compressing it to [0, 1) without changing the shape.
>
> I think you need to consider more strongly what you are actually trying
> to solve, go back to trying to understand the requirements before
> writing the program. Because I don't think that "Choose an item from
> this finite list according to an infinite distribution" is meaningful.
>
>
> --
> Steven
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/5SRPE5QGTXJT3VLQFQFF4QXMVWH7DS3G/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MFLJWVSOERUWQWN5JNN46N2MQW66YITO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to