(Original creator: adriang)

If you are not aware of it, Rik Lewis has a great blog about Uniface. I was quite interested in a recent post about the generation of random numbers. We don’t *officially* have this in Uniface. I don’t know why we don’t (probably something related to C++ across multiple platforms from the dark ages). I’m interested to find out if this is something that we should put in the product (I’m assured it’s not too difficult), but I’m curious to know some use cases. The obvious one would be to generate primary keys, although there are other ways to do this. But also things like how long would it need to be? 10, 20, 50 characters or should it be something like $random(10) which specifies 10 characters? Comments welcome..


  1. It would be great to have a random number generator. I often need one when generating test data. There are always workarounds, but having a random generator would definitely make life easier. For starters I would already be very happy with a simple one: just numeric with a minimum and maximum value. But please leave some room in the syntax so it can be enhanced to generate random strings as well (length, upper/lower/camel case, alphabetic/alphanumeric/special characters). Maybe it is not so important that exactly the same algorithm is used on different platforms. I can't think of compatibility issues in the data: it is random!
  2. When you say you don't officially have it, does that mean there's an unofficial way we can do it? I think this should definitely be a quick win, and something that should be relatively straight forward to add natively. Usually how this works for random numbers would be where "$random(100)" would return a random number between 0 and 100. Maybe if you're looking at including random strings (which would be interesting) then there should be a $randstr and $randnbr? Sticking with numbers is much more straightforward of course (as you don't have to specify what kind of character set you want included) and would usually be a min/max value (or just max), rather than a length.
  3. A few months ago I wrote a random number generator to support the creation of technical keys. The key fields were stored as a 10 character strings and so I allowed for uppercase and lowercase letters as well as numbers for a possible range of 62 ** 10 values. We limited ourselves to these characters and not the full ASCII set because the technical keys would be exposed in URLs in a REST interface and we didn't want to suffer through encoding and separator issues. I used a linear congruential generator algorithm with the values from MMIX (see which thanks to Uniface allowing very large integers to be handled as strings was pretty easy to implement. So I think a random number generator would be a useful addition, but it has to handle very large numbers to support technical keys. I don't mind if the function only returns numbers because I can pack that into our own patterns, but if it could produce a random string then that would be great.
  4. We do have a simple procedure since UnifAce 7 (original source by Park and Miller in ACM June 1988) Input is an integer MAX Ouput is an integer between 0 and MAX (0<=return_value<MAX) For technical keys $UUID will make a good job Ingo