|
|
|
|
|
|
|
|
|
|
|
|
|
|
Random number generation using LotusScript (continued)
Random number generators are usually initialized using a seed value. Initializing the generator with the same seed will produce the same sequence of random numbers. Use another seed value if a different sequence is needed. Many generators will carry the seed burden themselves by using the system clock time as the seed. LotusScript provides the seed mechanism by way of the Randomize function.
Randomize
The Randomize function seeds the Rnd function. It accepts an optional numeric parameter; the system timer is used if no seed value is specified. The Randomize function is called before the Rnd function. The next example shows it in action.
Dim out As String
Dim cr As String
Dim x As Integer
cr = Chr(13)
Randomize 31
For x = 0 To 9
out = out + Cstr(Rnd) + cr
Next x
Msgbox out
|
The resulting output is shown in Figure D.
FIGURE D
 
Here is the output from this example. Roll over picture for a larger image.
An important point concerning the previous example is the behavior of the script. The script returns the same sequence of numbers every time it's run (try it). This is the designed behavior of the functions. A different seed value should be used every time to ensure different (random?) values. The next example uses a random number as a seed value.
Dim out As String
Dim cr As String
Dim x As Integer
Dim seedS As Single
Dim seedI As Integer
cr = Chr(13)
Randomize Rnd
For x = 0 To 9
out = out + Cstr(Rnd) + cr
Next x
Msgbox out
|
The last example seems like a good idea, but predictable results may appear. The only true way to ensure unpredictable results is using the system timer as the seed value. This is accomplished by providing no seed value with the Randomize function. The next example shows how it's used by generating numbers between zero and ninety-nine.
Dim out As String
Dim cr As String
Dim x As Integer
Dim temp As Single
Dim rounded As Integer
cr = Chr(13)
Randomize
For x = 0 To 9
temp = Rnd
rounded = Round((temp * 100), 0)
out = out + Cstr(rounded) + cr
Next x
Msgbox out
|
The resulting output is shown in Figure B.
FIGURE E
 
Here is the output from this example. Roll over picture for a larger image.
Random numbers have many uses in business applications. A random drawing may be necessary or a random number may be needed for a document. Whatever the case, LotusScript provides the facilities to meet the demand.
Conclusion I hope this article has provided some insight into random number generation in LotusScript. The fact is random number generators do not produce truly random sequences according to mathematic theories; they are often called pseudo-generators. This should not cause problems in your Domino and Notes applications. Knowing the behavior of the Rnd and Randomize functions will allow them to be better utilized when needed.
Product availability and resources For the article, "Using LotusScript to manage email overload," by Charles Masino and Kedrick Jones in the January 2000 issue of DominoPower, visit http://www.dominopower.com/issues/issue200001/mailoverload001.html.
For the article, "LotusScript agents and the Web," by Chris Stoner in the February 2000 issue of DominoPower, visit http://www.dominopower.com/issues/issue200002/agent001.html.
For the article, "Lotus Notes 5.0 LotusScript enhancements," by Tony Patton in the November 1998 issue of DominoPower, visit http://www.dominopower.com/issues/issue199811/enhance001.html.
For the article, "Using recursion in LotusScript," by Greg White in the March 2000 issue of DominoPower, visit http://www.dominopower.com/issues/issue200003/recursion001.html.
Easy, flexible article reprints ZATZ now offers a quick, easy, flexible and inexpensive way to use article reprints in your marketing and promotion efforts. You can now get article reprints for a one-time fee of only $200. For details, visit http://mediakit.zatz.com/reprints.
|
DominoPower Contributing Editor Tony Patton is a Domino enthusiast with plenty of experience in Domino, Java, XML, and any other hot buzzword. He has written two books (Practical LotusScript and Domino Development With Java) and is a long-suffering Philadelphia sports fan. Drop him a line at aspatton@bellsouth.net.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Advertisement --
Find unused Lotus Notes groups and clean up your address book
Have you ever wanted to get rid of old Lotus Notes groups that were cluttering up your address book, but you weren't sure if they were used? Find Unused Groups can help.
Find Unused Groups will check your ACL, mail, multi purpose and server groups to help you determine if they are used, and who uses them.
Learn how to easily clean up your address book. |
-- Advertisement --
Struggling with exporting Notes data to spreadsheets? No More!
Try IntelliPRINT, The world's leading Reporting, Dashboards, and Analysis solution for Notes & Domino
- Don't spend unproductive time maintaining different versions of the same spreadsheet
- Preserve data integrity and security in multi-user environments
- Create reports in minutes INSIDE Notes
- Get freedom from iterative report requests, deliver self-serve capabilities
Experience Reporting, Dashboards, and Analysis INSIDE Notes.
Try IntelliPRINT NOW! |
|
|
|
|
|
|
|
|
|
|