How to generate random number in Siebel eScript?

Recently I had a requirement to generate non-repetitive random numbers in siebel escript. I searched the siebel tools help and found Clib.rand() function to the rescue. And using it was also very simple.

var temp = Clib.rand();
TheApplication().RaiseErrorText(temp);


But this function do not guarantee the non-repetitive output. Instead of building any complex algorithm, to get non-repetitive random number i used Date object and getTime method. As time is allways incrementing and it never looks back :) i used this as my random number.

This method returns the date-time, in milliseconds, of the Date object.

var aDate = new Date().getTime();
TheApplication().RaiseErrorText(aDate);

Try it out it never fails.
One point to note here is that if requirement is to get series of random number in loop, then you have to add some delay of about a millisec so that system time is updated. njoy!!

Comments (4)

Loading... Logging you in...
  • Logged in as
njoy the syntax high lightening in code snippets!
Sebastian's avatar

Sebastian · 779 weeks ago

To get a unique identifier, it's also possible to use the business service "SIS OM PC Service", method "Get Next RowId" and retrieve a new unique Siebel row id. Then use the expression function RowIdToRowIdNum(...) to transform the row id to a number.
1 reply · active 779 weeks ago
Great Thanks Sebastian, for sharing this wonderful service.
Can you please also share how we can use this RowIdToRowIdNum function ? is it available on the application object? or it will automatically work in workflow expression?

- Tejeshwer
Chapelain36's avatar

Chapelain36 · 611 weeks ago

The second feature with time is usefull. Very thanks.

Post a new comment

Comments by

Other Siebel Blogs

siebel-admin-l @ IT - toolbox

siebel-dev-l @ IT - toolbox