ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Random num generation problem

Post new topic  Reply to topic
 Random num generation problem « View previous topic :: View next topic » 
Author Message
sathishkotturi
PostPosted: Fri Feb 03, 2017 10:12 pm    Post subject: Random num generation problem Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Fri Feb 03, 2017 10:44 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
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
View user's profile Send private message Send e-mail
smdavies99
PostPosted: Sat Feb 04, 2017 12:10 am    Post subject: Re: Random num generation problem Reply with quote

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
View user's profile Send private message
gbaddeley
PostPosted: Sun Feb 05, 2017 5:03 pm    Post subject: Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2495
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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Random num generation problem
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.