Random number help
Thomas Grops
twgrops at googlemail.com
Wed Nov 23 14:39:25 EST 2016
On Wednesday, 23 November 2016 19:30:04 UTC, Thomas Nyberg wrote:
> On 11/23/2016 02:17 PM, Thomas Grops via Python-list wrote:
> > I need a way of generating a random number but there is a catch:
> >
> > I don't want to include certain numbers, is this possible?
> >
> > random.randint(1,100) works as it will randomly pick numbers between 1 and 100 but say i don't want 48 to come out is there a way of doing this. It needs to be an integer too so not a list unless there is a way to convert list to int
> >
> > Many Thanks Tom
> >
> If you specifically want to exclude 48, you could create the list of
> acceptable numbers and make a random choice from it. For example:
>
> >>> import random
> >>> l = list(range(1, 48)) + list(range(49, 101))
> >>> random.choice(l)
> 64
>
> Cheers,
> Thomas
Thankyou, I just tried this but it seems to be printing every value excluding 48, I am just after a single value
More information about the Python-list
mailing list