Rocket Uniface User Forum

 View Only

A solution to generate random values

By Kathy Larson posted 12-06-2023 10:01


Author: Weiye Li

In the fast-paced world of software development, efficiency and convenience are paramount. As a low code application development platform, Uniface has been a trusted tool for many developers; however, sometimes there can be inconvenience: the absence of a built-in random function. But today, we are happy to introduce you to the solution to this inconvenience: the new $random function. 

The Past: Uniface's Random Conundrum 

For a while, Uniface developers faced a common challenge: the lack of a built-in random function to generate random values. This limitation meant that developers often had to resort to external software or employ unconventional methods to generate random data. It required extra effort and workaround solutions. 

The Present: Embracing the $random function 

By introducing the $random function, we have removed the need for external dependencies and intricate workarounds. Developers can now generate random data with ease and precision, making their coding tasks more efficient. 

Function prototype: $random (Topic {, Length}) 

The $random function comes with a straightforward function prototype. To use it, simply follow the format: $random (Topic {, Length}). Let's explore what this function can do. 

What the $random function can do: 

  1. Generating Random Strings or Raw Data: With the $random function, developers can effortlessly create random strings or raw data of a specified length. This feature is particularly useful in scenarios where random data is required for testing or encryption. 

  1. Generating Random Numeric Values: Need random numeric values between 0 and 1? The $random function can generate random numeric numbers, making it an invaluable tool for statistical analysis, simulations, and more. 

Usage Samples 

To get a feel for how the $random function works, consider the following examples:  

; len is a numeric 

; RandomNum is a numeric 

; ResStr is a string 

; ResRaw is a raw 

len = 15 

RandomNum = $random("Number") ; RandomNum = 0.73350636388324717805777460567361290307 

Strlen = $length(RandomNum) ; Strlen= 40 

ResStr = $random ("String", len) ; ResStr = "usVf#G6"jj{kN4a" 

Strlen = $length (ResStr) ; Strlen= 15 

ResRaw = $random ("Raw", len) ; ResRaw = "|i|3Np{]1Rz{O|Y+|${-|kr" 

Strlen = $length (ResRaw) ; Strlen= 15 


If you want to get detailed information, please visit our online documentation. 

We are confident that you will find it to be a valuable addition to your development toolkit, making random data generation easier and more efficient than before.