Today's post is a bit unique and should leave some OPA developers at Oracle scratching their heads and asking "why?"  My answer - "why not?"

 

Have you ever wanted to select questions at random to ask during an OPA interview, in order to test knowledge?  Can you think of any other reason to have OPA generate Pseudo-Random numbers?  I did - I quickly wrote a game using OPA.

 

Sure, you could use Rulescript, an API, or Javascript to get random numbers, but I chose to implement the common Linear Congruent Generator for random numbers using OPA itself.  I use the same routine and parameters as the Java libs, Posix, etc...  So, I think this is a pretty good random number generator.

 

My "Random Numbers" project is attached and also the classic game of "Bagels" from the 1978 issue of ATARI magazine.   I implemented the game using OPA and the random number generator so that example random number generator usage can be explored.  Plus - its a game.

 

The random numbers project from this blog is easily included in other projects as an "inclusion". 

 

There is a "Random Number Initialization.docx" rule file that has the following parameter settings for the random number generator.  These example settings would generate 100 random values between 1-10,000 inclusive.  It puts the values into "the random number value" in the random number entity.  You are expected to change these settings for your project.  The other rule file contains my random number generator logic and shouldn't be touched unless you know what you are doing. 

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Random number settings.  Separate from the rules, in case I want to change the random number engine…

 

These next 4 values can be overridden to provide more / less random numbers and range… the rndm seed defaults to a value from the date / time.

the seed = the rndm time seed

the rndm number count = 100

the rndm range low = 1

the rndm range high = 10000

 

if the following statement is "the random values are unique", then the rndm number count must be less than the random number range.  This generates non-repeating numbers.

 

This next statement must be either:

  • the random values are unique
  • the random values are not unique

the random values are unique