Yes, I use this undocumented function as well append with a timestamp. I really hope TM1 v12 can have some sort of UUID function but unfortunately, I don't think it will be included this time. :(
Original Message:
Sent: Fri June 02, 2023 04:53 AM
From: George Tonkin
Subject: Cognos TM1 Rand() function – it is NOT quite random
Maybe another approach to deriving a unique reference is to use the undocumented MilliTime function.
This will return a numeric value like 1813725061
If you want to be really sure of uniqueness, you could go with something like the below:
sView=GetProcessName | Str(MilliTime() * Rand(), 10, 0 ); |
MilliTime is supported and have it on good authority that it is not going anywhere. In PAW, you would just need to ignore the error PAW returns as PAW is not aware of this function. Your process will however save and execute.
------------------------------
George Tonkin
Business Partner
MCI Consultants
Johannesburg
Original Message:
Sent: Fri June 02, 2023 04:39 AM
From: Emil Malmberg Fosdal
Subject: Cognos TM1 Rand() function – it is NOT quite random
Hi Renaud,
I have had the same issue as well.
If you have a counter, a way to handle can also be to append the RAND() number every 65k records. If not, appending multiple RAND()'s can also be a solution, as they will have multiple seeds and limit the chance of overlapping numbers.
------------------------------
Emil Malmberg Fosdal
Solution Architect
CogniTech A/S
Original Message:
Sent: Fri June 02, 2023 03:59 AM
From: Renaud MARTIAL
Subject: Cognos TM1 Rand() function – it is NOT quite random
Hello,
I might add that usually we do not really need random numbers, but rather a way to generate unique identifiers to create temporary objects in TI processes (well, it was before PA capabilities to build really temporary views and subsets).
The classic way is to build a string with some contextual information, a timestamp and a random number, which is often quite sufficient for this purpose.
In our case, however, it seemed to be insufficient, as we have a tremendous number of processes that are executed simultaneously, and some time ago it appeared twice that this method generated the same string, which resulted in a lock in the TM1Server.
So the point should be to have the capability to get an ID which is guaranteed to be truly unique, similar to a UUID.
Fortunately, there's a way to achieve this with the availability of the RunProcess function, which returns a JobID.
Since it's built by the PA server itself - well, the part that handles RestAPI calls - and can be used to uniquely identify a TI Process call, it's by design quite unique.
So a nice way to achieve this UniqueID retrieval is to use RunProcess to execute a process that does nothing, and use its return value.
Regards,
------------------------------
Renaud MARTIAL
PA Applications Manager / Tech lead
L'Oréal
Original Message:
Sent: Fri June 02, 2023 02:18 AM
From: Emil Malmberg Fosdal
Subject: Cognos TM1 Rand() function – it is NOT quite random
Hi Morgan,
It is impossible for any computer to generate truly random numbers, as nothing happens randomly when it comes to code. Random numbers are actually generated by a equation, based on a "seed" which are often time based. At some point the equation will start over, that will always happen. In this case, it seems to be at 65,536 :-)
------------------------------
Emil Malmberg Fosdal
Solution Architect
CogniTech A/S
Original Message:
Sent: Thu June 01, 2023 05:43 AM
From: mvp morgan
Subject: Cognos TM1 Rand() function – it is NOT quite random
Hi, all
Just came across this. I tested in our PA server and it is still the case. Just wondering the reason behind this?
https://everanalytics.wordpress.com/2015/07/05/cognos-tm1-rand-function-it-is-not-quite-random-after-all/
IBM Cognos TM1 Rand () function can generate up to 65,536 unique numbers. Thereafter it starts repeating the numbers. To test this behavior, enter below piece of code in the prolog of a TI process and execute it.
i = 1;
iMax = 65536;
WHILE ( i <= iMax *2 );
IF (i <= iMax);
vFile = 'sk1.txt';
ELSE;
vFile = 'sk2.txt';
ENDIF;
vFile = GetProcessErrorFileDirectory | vFile ;
AsciiOutput (vFile, NumberToString (Rand()) );
i = i + 1;
END;
------------------------------
mvp morgan
------------------------------