|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Random num generation problem |
« View previous topic :: View next topic » |
Author |
Message
|
sathishkotturi |
Posted: Fri Feb 03, 2017 10:12 pm Post subject: Random num generation problem |
|
|
Newbie
Joined: 06 Dec 2016 Posts: 5
|
Hello......In my application I need a Unique ID generation for the customer booking service.
So I have used RAND() Function...Its working But seems repeating sometimes...
DECLARE I DECIMAL 1;
DECLARE J DECIMAL;
SET I=10*exp(10);
SET J=FLOOR(Rand()*I+1);
SET I=CAST(J AS INTEGER);
SET OutputRoot.XMLNSC.Create_Order_Response.UniqueId=J;
DO I need to require any changes with above code......for perfect generation of random number.....
 |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Feb 03, 2017 10:44 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Why do you use a random generator when the broker has functions for just doing that. Look at the UUID functions UUID as Char and UUID as Blob  _________________ MQ & Broker admin |
|
Back to top |
|
 |
smdavies99 |
Posted: Sat Feb 04, 2017 12:10 am Post subject: Re: Random num generation problem |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
sathishkotturi wrote: |
Hello......In my application I need a Unique ID generation for the customer booking service.
So I have used RAND() Function...Its working But seems repeating sometimes...
DECLARE I DECIMAL 1;
DECLARE J DECIMAL;
SET I=10*exp(10);
SET J=FLOOR(Rand()*I+1);
SET I=CAST(J AS INTEGER);
SET OutputRoot.XMLNSC.Create_Order_Response.UniqueId=J;
DO I need to require any changes with above code......for perfect generation of random number.....
 |
Well done. This is going to happen in any randum number generator if you use the same seed. I first came upon this while I was at University a long, long time ago.
To overcome this in other environments use a seed based upon something that changes regularly like oh, the current timestamp.
As has been said, IIB has tools that will generate random things called UUID's. These will be far more random than you might expect.
Why not try a few things using UUID's.
If this is not good enough please tell us the limits and pattern of the random number that you are trying to generate. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
gbaddeley |
Posted: Sun Feb 05, 2017 5:03 pm Post subject: |
|
|
 Jedi Knight
Joined: 25 Mar 2003 Posts: 2538 Location: Melbourne, Australia
|
By definition, a random number generator can produce the same number many times. PRNG implementations will do this with a defined period or probability.
As suggested, use a method that is guaranteed to produce unique values within the constraints of the method. _________________ Glenn |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|