HALBURN Posted October 3, 2014 Posted October 3, 2014 I need a way to create 2000 unique 5 digit random numbers that do not being with a zero. I am trying to generate them with a looping script but I am running into two problems. The first problem is that I keep getting duplicates which throws up and error because of the unique validation that I have set for the field. The second problem is that the 5 digit number cannot begin with a zero. This is my current calculation: SerialIncrement ( "00000" ; Int ( Random * 99999 ) ) Ideally I would like the script to automatically recreate another number if it encounters a duplicate instead of throwing up an error. Any help would be greatly appreciated. Thanks.
comment Posted October 3, 2014 Posted October 3, 2014 To generate a random 5-digit number that does not begin with zero (i.e. an integer between 10,000 and 99,999, incl.) = Int ( Random * 90000 ) + 10000 To eliminate duplicates, you must compare the new number with a list of numbers generated so far and add the new number to the list only if it's not already there. With only 2,000 numbers to generate, you could keep the list in a variable and use the FilterValues() function to make the comparison. Once you have the required 2,000 values, exit the loop and move to creating a record for each value in the list (assuming that's where you need them). 1
Rupert Snyman Posted October 5, 2014 Posted October 5, 2014 Could you sort them and step through with a counter? Your sort could introduce the "randomness"
Recommended Posts
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