|
|
|
|
|
|
|
|
|
|
|
|
|
|
PROGRAMMING POWER
Random number generation using LotusScript
By Tony Patton
DominoPower has received countless emails requesting more information on LotusScript. This month we begin to address these issues. A frequent solicitation involves random number generation, and it is the focus of this column.
Random number generation A good question to ask about this subject is what does random mean? A dictionary definition of random is: "having no specific pattern, purpose, or objective."
However, programming is a bit different. Most developers have encountered situations where a random number generator is needed, so we need to know what qualifies as random.
A true random number generator has three important properties:
- It is unbiased: All values, regardless of sample size, are equiprobable;
- It is unpredictable: It is impossible to predict the next output, given all previous outputs;
- It is unreproducible: Two of the same generators, given the same starting conditions, will produce different outputs.
Random number generation in LotusScript Now let's turn our attention to random number generation within the confines of LotusScript.
LotusScript offers two functions for random number generation: Rnd and Randomize. We'll consider Rnd first.
Rnd
Rnd is an abreviation for random. It generates a real number greater than zero and less than one. Here is a simple mathematic representation of its behavior.
0 < random_number_generated < 1
|
The syntax is very simple:
The parentheses are optional if no arguments are passed. The first example, below, puts the Rnd function to use; a for loop is used to generate ten random numbers. A message box displays the results.
Dim out As String
Dim cr As String
Dim x As Integer
cr = Chr(13)
For x = 0 To 9
out = out + Cstr(Rnd) + cr
Next x
Msgbox out
Print Rnd
|
The resulting output is shown in Figure A.
FIGURE A
 
Here is the output from the first example. Roll over picture for a larger image.
The return type of the Rnd function is Single. Single is a four byte floating-point value. That is, it's a real number. The result can be multiplied and rounded to receive an integer value. The next example alters the previous code to produce a number between zero and nine.
Dim out As String
Dim cr As String
Dim x As Integer
1.Dim temp As Single
Dim move_decimal As Single
Dim round_value As Integer
2.cr = Chr(13)
3.For x = 0 To 9
4. temp = Rnd
5. move_decimal = (temp * 10)
6. round_value = Round(move_decimal, 0)
7. out = out + Cstr(round_value) + cr
Next x
8.Msgbox out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Advertisement --
Sophisticated Meets Simple For Document Management
Share. Control. Manage.
Documents, emails, and content in the context of how work is done.
Native to Lotus Domino. The User Experience unseen for Lotus Domino.
Do more with less. Really.
See the possibilities Docova unleashes for Lotus Domino. |
-- 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! |
|
|
|
|
|
|
|
|
|
|