Nelly Posted April 28, 2004 Posted April 28, 2004 Hi guys On creation of a new record I need FM to generate a unique random password with the format of four numerics (0-9) and then six alpha characters (a-z). Can anyone suggest how I might go about doing this? Seems like something so simple but cannot think where to start. Thanks.
The Shadow Posted April 28, 2004 Posted April 28, 2004 Nelly, Middle( "0123456789abcdefghjkmnpqrstuvwxyz"; (Random * 33); 1 ) will generate a single random letter/number. I dropped "i", "o", and "L" from the list since they often confused.
jfmcel Posted April 28, 2004 Posted April 28, 2004 Your calc is ... Middle("0123456789"; Int(Random*10; 0)+1;1) & Middle("0123456789"; Int(Random*10; 0)+1;1) & Middle("0123456789"; Int(Random*10; 0)+1;1) & Middle("0123456789"; Int(Random*10; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25; 0)+1;1)
Nelly Posted April 30, 2004 Author Posted April 30, 2004 Excellent! Thanks so much for this. I do not understand it but it works perfectly ;-) How does it ensure that the number will be unique? Or doesn't it? Cheers.
Nelly Posted April 30, 2004 Author Posted April 30, 2004 Hiya jfmcel One thing I noticed on your fantastic calculation was that when the first random numeric was a zero it was being omitted in the field display. So I changed the first line of your script to dle("123456789"; Int(Random*9; 0)+1;1) & This way the first generated number will never be a zero. See below. Middle("123456789"; Round(Random*9; 0)+1;1) & Middle("0123456789"; Round(Random*10; 0)+1;1) & Middle("0123456789"; Round(Random*10; 0)+1;1) & Middle("0123456789"; Round(Random*10; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Round(Random*25; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Round(Random*25; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Round(Random*25; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Round(Random*25; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Round(Random*25; 0)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Round(Random*25; 0)+1;1)
jfmcel Posted May 2, 2004 Posted May 2, 2004 Oops - I modified my calc to fix a problem introduced by using Round() and not Int(), but I screwed it up in the process. The correct answer is... Middle("123456789"; Int(Random*9)+1;1) & Middle("0123456789"; Int(Random*10)+1;1) & Middle("0123456789"; Int(Random*10)+1;1) & Middle("0123456789"; Int(Random*10)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25)+1;1) & Middle("qwertyuiopasdfghjkzxcvbnm"; Int(Random*25)+1;1)
Oldfogey Posted May 3, 2004 Posted May 3, 2004 By definition, you cannot have both random and unique. Once having arrived at a random number by the methods described, you need to check for uniqueness, probably with a self-join lookup. Then re-do the calc if it's not unique. I think you could do this in a calculation field but it's scotch time, not mind time so the solution is left as an exercise ......
jfmcel Posted May 4, 2004 Posted May 4, 2004 The chances of the password not being unique are so extremely small that it should not ever be a concern. [For this method of generating a random password, the chances of any two passwords being the same is 1/(9*10^3*25^6) or about one in 2 trillion.]
Oldfogey Posted May 5, 2004 Posted May 5, 2004 The chance of getting a duplicate is not relevant. I recently had reason to develop some thousands of random six-digit numbers and was amazed at the frequency of duplicates. (Try throwing a simple dice and see how often you get duplicates.) Depending on how important uniqueness is, checking for duplicates could be essential. We have a lottery here which has a jackpot based on the winning number being drawn on a second draw. The odds are, I think, 1 in 1 trillion. It has been won and there have not been anything like 1 trillion lotteries. One of the classic problems in program development is trying to cover all those so-called 'impossible'/'never happens'/'extremely unlikely' situations. They happen on day 1 of live running.
The Shadow Posted May 5, 2004 Posted May 5, 2004 This is the birthday paradox in action: http://en.wikipedia.org/wiki/Birthday_paradox Since you want no duplication between any two passwords, and the number of pairs of passwords that must be unique is growing fast.
jfmcel Posted May 7, 2004 Posted May 7, 2004 We are talking about passwords here. So why should duplicate passwords ever be a concern. [FM 7 Account Names would be a different story. The solution there is to let FM return an error when you try to create the account.]
Oldfogey Posted May 10, 2004 Posted May 10, 2004 I must have been asleep when I wrote that last post. Your calculation of the 'odds' is not correct. The apparent 'odds' are much lower than than that - 1 in zillions of trillion. However, your calculation does not generate genuine random numbers. The chances of getting a duplicate depend on the number of records being generated. To use some simple numbers - a 10-sided dice need 5 random numbers Throw the dice 5 times and you will almost certainlky get duplicates. I can't remember the specific formula but the chance of getting two identical numbers in 5 tries is close to 1. (Ever seen the party trick of finding out how many people ina room have the same birthday? In a room of forty, you have almost certainy.)
Oldfogey Posted May 14, 2004 Posted May 14, 2004 Thanks for the link, Shadow. I can just about remember when I knew that stuff. Also, to jfmcel, we didn't ask for unique passwords. Nelly did.
Recommended Posts
This topic is 7501 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now