RE: Help creating a random string in Perl




Look at crypt();
$ perldoc -f crypt is a good

-----Original Message-----
From: p46921x@xxxxxxxxxxx [mailto:p46921x@xxxxxxxxxxx]
Sent: Tuesday, June 12, 2007 3:39 PM
To: beginners@xxxxxxxx
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: beginners-unsubscribe@xxxxxxxx For additional
commands, e-mail: beginners-help@xxxxxxxx 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.


.



Relevant Pages

  • Re: Added hashes.
    ... >computable as it is for either hash alone. ... If you combine million byte values from digests (Good-hash+ Bad-hash, ... an OTP - random string derived from cosmic radiation. ... If you combine the English phrase with a cosmos-derived random string, ...
    (sci.crypt)
  • Re: Fast way to determine if a string contains a member of a list of strings
    ... Using the StateMachine method on 359 strings and a source string of ... Have you tried testing the worst-case scenario, which is a source string that has zero matches? ... The only way I could see the state graph taking almost 2.5 seconds to process a 47 character string is if you are including the time it takes to build the state graph. ... Even assuming 10-character strings on average with _no_ overlapping characters, that's only 35900 iterations to build the graph. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: look-ahead search for overlapping
    ... I did not realize that random string of words represented ... > this is a is a test a test for test for fun for fun ... "Reply" at the bottom of the article headers. ...
    (comp.lang.perl.misc)
  • Re: Random String
    ... random string? ... That was rather a good example of why some application programmers, ... If I had been *trying* to implement security software, fine, ...
    (comp.lang.c)
  • Re: Fastest way to search a string for the occurance of a word??
    ... >> characters of the random string to check the RNG is coming up with the ... Well we're at least dealing with the same string then:) ... 4.52s for regular expressions, for a million iterations (one test ...
    (microsoft.public.dotnet.languages.csharp)