Python Forum
how to put string in random order
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to put string in random order
#1
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 ?
Reply
#2
shuffle it with random module.
>>> import random
>>> 
>>> s = list('184uwkdf')
>>> random.shuffle(s)
>>> ''.join(s)
'f8u4k1wd'
>>> random.shuffle(s)
>>> ''.join(s)
'fw8du1k4'
Reply
#3
(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 :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sample random, unique string pairs from a list without repetitions walterwhite 1 474 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  generating random string unique forever Skaperen 5 2,356 Aug-20-2021, 07:15 AM
Last Post: Gribouillis
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,847 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 2,442 Oct-14-2019, 10:40 AM
Last Post: perfringo
  Replace a list or string element with a random one.. pianistseb 3 2,462 May-09-2019, 08:24 AM
Last Post: buran
  problems with random number/string PrasadPython 3 2,613 Mar-01-2019, 06:00 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020