Python Forum

Full Version: how to put string in random order
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
so I have a randomly generated string consisting of numbers and letters , it looks like 184uwkdf, how do i make it random like 1u4df8kw ? Is there a function for it ?
shuffle it with random module.
>>> import random
>>> 
>>> s = list('184uwkdf')
>>> random.shuffle(s)
>>> ''.join(s)
'f8u4k1wd'
>>> random.shuffle(s)
>>> ''.join(s)
'fw8du1k4'
(Aug-23-2018, 11:34 AM)snippsat Wrote: [ -> ]shuffle it with random module.
>>> import random
>>> 
>>> s = list('184uwkdf')
>>> random.shuffle(s)
>>> ''.join(s)
'f8u4k1wd'
>>> random.shuffle(s)
>>> ''.join(s)
'fw8du1k4'

Thanks ! You really helped :)