| | |
Function that creates random changes in a string??
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2005
Posts: 4
Reputation:
Solved Threads: 0
Hello!!
Does anybody know how to create a function that randomly changes elements in a string?
And: does anybody know how to set the chances for the type of changes?
I've tried to look it up in tutorials, but since I'm a beginner, most of the time creating random outputs, requires a lot more Python knowledge than I currently have.
Thanks in advance!
Does anybody know how to create a function that randomly changes elements in a string?
And: does anybody know how to set the chances for the type of changes?
I've tried to look it up in tutorials, but since I'm a beginner, most of the time creating random outputs, requires a lot more Python knowledge than I currently have.
Thanks in advance!
•
•
Join Date: May 2005
Posts: 215
Reputation:
Solved Threads: 16
what kind of changes are you looking for. lets say you have the string 'the dog went home' , how would you want that changed? Changed is a vague term.
you may want to use random.choice it will make a random choice of an element.
here is an example
[php]
choices = ('a','b','c','d','e','f','g','h','i','j','k')
random.choice(choices)
[/php]
this will choose one of the elments randomly.
you may want to use random.choice it will make a random choice of an element.
here is an example
[php]
choices = ('a','b','c','d','e','f','g','h','i','j','k')
random.choice(choices)
[/php]
this will choose one of the elments randomly.
•
•
Join Date: Jun 2005
Posts: 4
Reputation:
Solved Threads: 0
There are three types of changes I want to make: deletion, insertion and replacement. I do know how these changes can be made with slices.
But the real problems are:
1) I can't get the changes to be completely random, while still asking for a string input and not integers.
2) When a change occurs (the user can request the number of changes), the type of changes should occur with certain chance ratios. I haven't found such a function yet in Python.
I am going to see what I can work out with random.choice. Thank you for your reply!
But the real problems are:
1) I can't get the changes to be completely random, while still asking for a string input and not integers.
2) When a change occurs (the user can request the number of changes), the type of changes should occur with certain chance ratios. I haven't found such a function yet in Python.
I am going to see what I can work out with random.choice. Thank you for your reply!
![]() |
Similar Threads
- question about php string function (PHP)
- Need help making simple random images (PHP)
- Help: need feedback on my Java assignment about thread sleep. It's already coded. (Java)
- Duplication (C++)
Other Threads in the Python Forum
- Previous Thread: Regular Exp
- Next Thread: Question about loops and strings
| Thread Tools | Search this Thread |
Tag cloud for Python
ansi assignment avogadro backend beginner binary bluetooth character cmd code customdialog cx-freeze data decimals dictionary drive dynamic error examples excel exe file float format ftp function gnu graphics gui heads homework http ideas import input java leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime program programming progressbar projects push py2exe pygame pyqt python random recursion recursive refresh schedule screensaverloopinactive script scrolledtext sqlite ssh statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial ubuntu unicode update urllib urllib2 variable wikipedia windows write wxpython xlib





