Search DominoPower's 10,675 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
What to look for in a Domino-based document management solution
Understanding Domino.doc end-of-life options
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
Top 10 ways to launch and build a Lotus consulting practice (with a little help from the Beatles)
Troubleshooting an OpenSuse Notes install
Incident report: denial of service attack against ConnectedPhotographer.com
Latest Lotus Headlines
SnTT - Enabling ALL the bells and whistles!
Tivoli Data protection causes Domino to crash
Fun when running DB2 CLP scripts
Introducing Flippr, the easy way to admin Quickr
DXL and fake security
Using search forms in IBM Workplace Collaborative Learning 2.7
Schmidt, Freed, and Gering on the OVF Toolkit
>> Read all the news
More from the ZATZ journals
Computing Unplugged: Eight steps to successful and reliable home backups
David Gewirtz Online: CNN commentary and analysis
OutlookPower: Can Outlook run when it's not running (and other mysteries)?
-- Advertisement --

Learn Notes and Domino 8 at your place and pace!
Learn Notes and Domino in your office and/or home! TLCC's highly acclaimed distance learning courses for users, developers, and admins will enhance your career and your resume.

The many included activities and demos will make you a pro! Expert instructor help is a click away.

Click here to try a FREE demo course!!

-- Advertisement --

Want The Top Lotus Experts By Your Side Without Paying Hefty Consulting Fees? Look No Further.
Like having a team of consultants by your side -- ones who have all the answers and never make mistakes -- THE VIEW gives you immediate access to field-tested instruction, guidance, and best practices from the brightest Lotus professionals around.

Join your peers who realize their Lotus technology is too important to let people from blogs and forums tell them how they should implement it, run it, and use it. THE VIEW is where only the world's top Lotus experts provide validated support to you on a weekly basis to ensure you work more efficiently, get more out of your Lotus technology, and stay clear of costly mistakes.

Check out the new instruction, tips, and best practices added to THE VIEW this week.

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