Search DominoPower's 11,323 Lotus-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
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:

Rnd()

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


1  ·  2  ·  3  ·  Next »
Other articles you might like
Home > Lotus Technologies > LotusScript (64 articles)
   When the debugger won't debug hidden code that isn't hidden
   What to do if the LotusScript debugger won't single-step over code
   Little known traps about Lotus Notes fields
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent DominoPower Articles
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Five trends for 2010
DominoPower TV Episode 1: Inside a strategy session with Teamstudio
More about Domino log files
Say goodbye to the Uh-Ohs. Long live the Tens.
Why your log.nsf might not be purging properly
Latest Lotus Headlines
Recommended Maintenance - Lotus Notes Traveler
Here are the slides and other materials from our Lotusphere session
Microsoft OCS awareness in Lotus Connections and Websphere Portal?
SnTT: XPages Blank Calendar Control (Part 2), adding data
Have your Lotus Notes calendar display multiple time zones
Sample Database for Microsoft Office and Lotus Symphony Integration
Symphony 3.0 beta signals another attack on Office
>> Read all the news
More from the ZATZ journals
Computing Unplugged: The iPad: Apple's latest heartbreaker
David Gewirtz Online: CNN commentary and analysis
OutlookPower: Running auto-respond rules when Outlook is closed
-- 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!

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login