Function that creates random changes in a string??

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2005
Posts: 4
Reputation: Lee Bel is an unknown quantity at this point 
Solved Threads: 0
Lee Bel Lee Bel is offline Offline
Newbie Poster

Function that creates random changes in a string??

 
0
  #1
Jun 29th, 2005
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!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 4
Reputation: Lee Bel is an unknown quantity at this point 
Solved Threads: 0
Lee Bel Lee Bel is offline Offline
Newbie Poster

Re: Function that creates random changes in a string??

 
0
  #2
Jun 29th, 2005
Btw, I think/hope that random.randrange could be helpful, but can't really figure out how I can make it work if I don't want to use integers...
Anyway; a link to a helpful tutorial would already be very much appreciated!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Function that creates random changes in a string??

 
0
  #3
Jun 29th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 4
Reputation: Lee Bel is an unknown quantity at this point 
Solved Threads: 0
Lee Bel Lee Bel is offline Offline
Newbie Poster

Re: Function that creates random changes in a string??

 
0
  #4
Jun 29th, 2005
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!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 4
Reputation: Lee Bel is an unknown quantity at this point 
Solved Threads: 0
Lee Bel Lee Bel is offline Offline
Newbie Poster

Re: Function that creates random changes in a string??

 
0
  #5
Jun 29th, 2005
The program is completed!
Thank you for the tip about random.choice! That was the missing link I couldn't get working...
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Function that creates random changes in a string??

 
0
  #6
Jun 29th, 2005
your welcome. I know very little, but am glad I had something to offer.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC