Look at crypt(); $ perldoc -f crypt is a good -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 12, 2007 3:39 PM To: [email protected] Subject: Help creating a random string in Perl
Hello, this is perl.beginners and I am really a beginner. This is also my first Google group post so if I am in the wrong group, I am sorry. I need to create a random combination of n-1 characters in a source string. For example if the string is ABcDeFG (7 characters) * I want to execute my perl script and get ABDeFG (6 characters) * I execute my perl script a second time and get GABcDe (6 characters) * I do it a third time and get AcBeDG (6 characters) * etc Also 1. Only characters in the source string are in the random string meaning if Z is not in my source string, it will not be in my random string. If A and B are in the source string, then at least one of them will be in the random string. 2. Each source string will only contain one of the same characters, ie ABcDeFG is a valid source string but there will be no source strings like ABBDeFG (as it contains two "B"s). 3. Each random string has one less character than the source string, ie the source string ABcDeFG has 7 characters but the random strings ABDeFG and GABcDe and AcBeDG have 6 characters. I can see how to generate a random number between 0 and 6 (meaning I can pick one of the 7 characters in my source string) by using "print int(rand(6))", but I don't know where to being on the second and third and fourth characters to and check that the random number hasn't already been chosen. Any help would be welcome. The more cryptic the better as it will force me to understand what the Perl does ;) Thank you Richard ps: I hope you don't mind but because I don't want spam, I have created this email address specifically to post to Google groups. If you are going to reply and I hope you do, please post to the Google group as my email address will not be monitored. ps: This isn't for school, it's sort of for fun for a program I am writing to do crosswords. ps: When I type perl - version, I see this as my version number "v5.8.8 built for i486-linux-gnu-thread-multi". ps: I have "Learning Perl 4th edition from Randal Schwartz". It is a good book but doesn't describe the type of things I need to do. I have access to Google but haven't been able to search a good link for the type of random string code to work from for my problem. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. -------- IRS Circular 230 Disclosure: Please be advised that any discussion of U.S. tax matters contained within this communication (including any attachments) is not intended or written to be used and cannot be used for the purpose of (i) avoiding U.S. tax related penalties or (ii) promoting, marketing or recommending to another party any transaction or matter addressed herein. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
