Example 1: Invoking a Randomizer

Previous Next

This example shows how an external component returns a random number for a lottery. Each customer booking a reservation automatically gets a free lottery number.

The component uses an input parameter to determine between which number and zero a random number must be found. In this example, lottery numbers between 0 and 10000 are returned.

The example uses the Travel Agency case .

To try out this example:

Locate the Samples/Usmath directory on your CD.

Read the README.TXT file for information on installing, running and inspecting the sample component.

Component Name

USMATH

Component Prog ID

USMathProject.USMath

Method

RANDOM

Physical Method

Random

Parameters of RANDOM

In - Long Integer

Return - Long Integer

RESERVATION Table

Add a LOTTERY_NO column based on a regular NUMBER(8) domain

Constraint

ASSIGN_LOTTERY_NO

Message: "Lottery no. assigned."

Transition Table: RESERVATION

Fire on Insert: Always

Fire on Delete: Never

Fire on Update: Never

UPDATE    reservation

SET     lottery_no =

(

   INVOKE usmath.random

   WITH

   SELECT 10000

)

 

Description of functionality:

The randomizer component returns a random integer between 0 and the input parameter.

Code of invoked subprogram:

Public Function Random(maxi As Integer) As Integer

   Randomize

   Random = Int(maxi * Rnd)

End Function