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 .
Component Name | USMATH |
Component Prog ID | USMathProject.USMath |
Method Name | RANDOM |
Physical Method Name | Random |
Parameters of RANDOM | In - Long IntegerReturn - Long Integer |
In the data model, to the RESERVATION table, add a LOTTERY_NO column based on a regular NUMBER(8) domain.
Constraint Name | ASSIGN_LOTTERY_NO |
Message | Lottery no. assigned. |
Transition Table | RESERVATION |
Fire on Insert | Always |
Fire on Delete | Never |
Fire on Update | Never |
Set the SQL statement to:
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