0

Pythons Random Modules

Can we use randint to randomize the series of values taken from a user for eg. print(""Enter five numbers) a=list(range(5)) for i in range(5): a[i]=int(input()) random.randint(a) print(a)

27th Jan 2018, 3:01 AM
Aniket Mane
Aniket Mane - avatar
14 Respuestas
+ 1
If you just want to randomize the order of the array, random.shuffle(a) will do the job.
27th Jan 2018, 3:15 AM
Chris
Chris - avatar
+ 3
randint(1,10)-5 would yield -4 to 5 to be added to entered number
27th Jan 2018, 3:14 AM
John Wells
John Wells - avatar
+ 2
We can, but your example won't work.
27th Jan 2018, 3:06 AM
Chris
Chris - avatar
+ 2
Definitely not like you coded it. Let's say I enter 10 30 40 20 0 as my five numbers. What kind of values would you like to see? +/-10. I assume you want your numbers to be somewhat related to the entered numbers.
27th Jan 2018, 3:09 AM
John Wells
John Wells - avatar
+ 2
By what amount
27th Jan 2018, 3:11 AM
John Wells
John Wells - avatar
+ 2
from random import shuffle as s a=list(range(5)) for i in range(len(a)): a[i]=int(input()) s(a) print(a)
27th Jan 2018, 3:25 AM
Aniket Mane
Aniket Mane - avatar
+ 1
Do it yourself, you'll learn more from it. You're on the right track.
27th Jan 2018, 3:10 AM
Chris
Chris - avatar
+ 1
ok tnx anyways now i atleast know its possible
27th Jan 2018, 3:12 AM
Aniket Mane
Aniket Mane - avatar
+ 1
i didn't get it @john wells
27th Jan 2018, 3:13 AM
Aniket Mane
Aniket Mane - avatar
+ 1
I think you want to print one of the 5 inputs? Remember that you access the single inputs in your array with a[i], so you have to randomize your i.
27th Jan 2018, 3:14 AM
Chris
Chris - avatar
+ 1
yus @chris
27th Jan 2018, 3:14 AM
Aniket Mane
Aniket Mane - avatar
+ 1
thnx @chris thats what i wanted
27th Jan 2018, 3:16 AM
Aniket Mane
Aniket Mane - avatar
0
thnx bt can u show me a proper example
27th Jan 2018, 3:07 AM
Aniket Mane
Aniket Mane - avatar
0
yes jus randomized
27th Jan 2018, 3:11 AM
Aniket Mane
Aniket Mane - avatar