Creating a random/unique number

Get a 4-digit random number.

Here was my need. I needed a 4 digit number, randomly assigned, but once assigned could not be equal to any number previously assigned. Originally, I also had the option for the user to choose how many numbers they needed, and with that I just added another check prior to going to the view to see if the number had been assigned. I ran some insane checks on how long this took...tried asking for 500 numbers within a range of only 1000 available, and it took almost a minute. But if this was the requirement everything would have been done differently.

I have this in a script library. Looking for a random number between 1000 and 9999, not yet assigned.


 Function uniqueRandom Dim w As NotesUIWorkspace Dim s As NotesSession Dim db As NotesDatabase Dim view As NotesView Dim getdoc As NotesDocument Dim tmp As Variant Dim tmp2 As String Dim curDoc As NotesDocument Set w = New NotesUIWorkspace Set s = New NotesSession Set db = s.CurrentDatabase Set view = db.GetView("(SavedNumbers)") Set curDoc = w.CurrentDocument.Document uniqueRandom = "" retry: tmp = Evaluate ("@Integer( (9999 - 1000 )*@Random + 1000)",curdoc) tmp2$ = Cstr(tmp(0)) Set getdoc = view.GetDocumentByKey(tmp2$,True) If Not getdoc Is Nothing Then Goto retry End If uniqueRandom = tmp2$ End Function
This was last published in September 2001

Dig Deeper on Domino Resources - Part 3

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close