Approach User Support homepage Approach User Support
Answers to Frequently Asked Questions about Lotus Approach
Examples LotusScripts
Example databases
Links to other Lotus Approach support services

[Return to contents]

Generating a random unused PIN number

Last updated: 6 Feb 1999

The following method for generating a random usused PIN number (ie a numeric password') was submitted by Mark Pearson:

My aim was to create a random number of 6 digits between 400000 and 999999, check that the number generated was not allocated to a record anywhere else and apply to a specific record for use. The reason I needed this was as a pin code for a call accounting system to be used by residents.

I used two variable numeric fields, two regular fields and three macros.

Macro one (This is actioned when on the record to receive the new number)

set var1 = studentID ' This sets a var field to the student or record id and will be used later to complete a find'

set var2 = Trunc(random()*1000000)+400000 'This creates the random number
but it is possible for it to be greater than 999999'

set var2 = If(Var2 > 400000 and Var2 < 999999, Var2, Var2 - 400000) 'This
reduces the value if was greater'

Find - Stored find 'create a stored find based on a worksheetview that has the var2 field and the field to get the random number. This find locates any record that matches the new generated number. If it finds a
match it continues this macro. If it finds no matches it goes to a macro2

Run macro3


Macro2
Find - Stored find that uses a worksheet view with the studentID field.
Finds the student that =@var1
Set - Random number field = var2


Macro3
Set var2 = Trunc(random()*1000000)+400000
set var2 = If(Var2 > 400000 and Var2 < 999999, Var2, Var2 - 400000)
Find stored find as per macro1
Run macro3

[Return to contents]

© Copyright, JohnBrown, Trademarks, Disclaimer, Acknowledgements.