944,184 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 3043
  • Python RSS
Jun 29th, 2005
0

Function that creates random changes in a string??

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lee Bel is offline Offline
4 posts
since Jun 2005
Jun 29th, 2005
0

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

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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lee Bel is offline Offline
4 posts
since Jun 2005
Jun 29th, 2005
0

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

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.
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005
Jun 29th, 2005
0

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

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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lee Bel is offline Offline
4 posts
since Jun 2005
Jun 29th, 2005
0

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

The program is completed!
Thank you for the tip about random.choice! That was the missing link I couldn't get working...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lee Bel is offline Offline
4 posts
since Jun 2005
Jun 29th, 2005
0

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

your welcome. I know very little, but am glad I had something to offer.
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Regular Exp
Next Thread in Python Forum Timeline: Question about loops and strings





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC