random.sample with long int items

Paul Rubin http
Wed Apr 12 09:44:29 EDT 2006


"jordi" <jpahullo at gmail.com> writes:
> I need the random.sample functionality where the population grows up to
> long int items. Do you know how could I get this same functionality in
> another way? thanks in advance.

Nothing stops you:

    >>> from random import sample
    >>> a = [n**25 for n in range(6)]
    >>> a
    [0, 1, 33554432, 847288609443L, 1125899906842624L, 298023223876953125L]
    >>> sample(a,2)
    [1125899906842624L, 298023223876953125L]
    >>> sample(a,2)
    [298023223876953125L, 847288609443L]
    >>> 

Is this what you were asking, or did you mean something different?



More information about the Python-list mailing list