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 » Generating Unique random number(INteger - 6 digits)

Post new topic  Reply to topic Goto page 1, 2  Next
 Generating Unique random number(INteger - 6 digits) « View previous topic :: View next topic » 
Author Message
vickas
PostPosted: Wed Oct 23, 2013 10:56 pm    Post subject: Generating Unique random number(INteger - 6 digits) Reply with quote

Centurion

Joined: 18 Aug 2013
Posts: 126

I need to generate a unique random number (must be a integer of only 6 digits )
I used RAND() function , but its generating decimal number.
Is there any other esql numeric function to generate unique random numbers ? If not , how to generate a integer(6 digits) using RAND() ?
Back to top
View user's profile Send private message
dogorsy
PostPosted: Wed Oct 23, 2013 11:19 pm    Post subject: Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

Quote:
how to generate a integer(6 digits) using RAND() ?

What does the documentation say ?... RAND generates a number between 0.0 and 1.0
Quote:
Is there any other esql numeric function to generate unique random numbers ?

Have you learned mathematics at school ? in particular MULTIPLICATION ?

RAND() {the correct maths operation here } and multiplier with the correct number of zeros...

Before asking basic questions you need:
1- read the documentation
2- think about the problem you want to solve and try to find a solution yourself.
Back to top
View user's profile Send private message
smdavies99
PostPosted: Wed Oct 23, 2013 11:21 pm    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

If the random number is between say 0.0001 and 0.99999 then

Multiply it by the number of digits you need so for 6 digits it is 1,000,000
Then cast to integer or use another method to drop the mantissa.

For a bit more randomness get another random number preferably with a different seed and multiply the second part by 1,000 and OR the results.

Not that hard really.
_________________
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
gs
PostPosted: Wed Oct 23, 2013 11:26 pm    Post subject: Reply with quote

Master

Joined: 31 May 2007
Posts: 254
Location: Sweden

There's no other ESQL function to provide this.
You'll need to write a function to do that - figure out how to use the RAND() function and write code to create the 6 digit string you need:
http://pic.dhe.ibm.com/infocenter/wmbhelp/v8r0m0/topic/com.ibm.etools.mft.doc/ak05373_.htm


Last edited by gs on Wed Oct 23, 2013 11:40 pm; edited 1 time in total
Back to top
View user's profile Send private message
dogorsy
PostPosted: Wed Oct 23, 2013 11:36 pm    Post subject: Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

Of course, there are other ways of doing it, for example, write your own function, you will need a prime number as a base and a simple algorithm.
Or you can use part of the timestamp, for example milliseconds.
you need to think what is better for you.
Back to top
View user's profile Send private message
vickas
PostPosted: Thu Oct 24, 2013 12:59 am    Post subject: Reply with quote

Centurion

Joined: 18 Aug 2013
Posts: 126

@ Dogorsy !!
I believe that am a gud math student !!
and i just wonder how kud you ask me to multiple with 10000 to my RAND result,etc ...
I was very particular of getting only 6 random digits.
RAND generated 0.001251258885 for the first time , and the second time it gave me 0.5635853144 , and if this is the case, multiplying with 1,000000 wud not give me the result with 6 digts al the time..
and I know that we can generate a 6 digit random number using current timestamp milisec,micro sec format !
Back to top
View user's profile Send private message
smdavies99
PostPosted: Thu Oct 24, 2013 1:06 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

Ok
0.001251258885 * 10exp6 = 1251.258885 drop mantissa and cast as char
= '1251'
Overlay onto '000000' gives '001251'

0.5635853144 * 10exp6 = 563585.3144 drop mantissa and cast as char = '563585'
Overlay onto '000000' gives '563585'.

You could always cast the number to a char using a relevant format clause that would include any leading zero's.(my preferred method but requires more investigation and testing to get it right)

Why don't you try a few things for yourself?
_________________
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
dogorsy
PostPosted: Thu Oct 24, 2013 2:07 am    Post subject: Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

vickas wrote:
@ Dogorsy !!
I believe that am a gud math student !!


maybe you are. Have you got to the times tables yet ? what about multiplication ?
Back to top
View user's profile Send private message
joebuckeye
PostPosted: Thu Oct 24, 2013 4:38 am    Post subject: Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 365
Location: Columbus, OH

And just because you can generate a random 6 digit number doesn't mean it will all be unique either. There is no telling when you will get a previously generated number.

Which is more important? Being random or being unique?
Back to top
View user's profile Send private message
dogorsy
PostPosted: Thu Oct 24, 2013 5:27 am    Post subject: Reply with quote

Knight

Joined: 13 Mar 2013
Posts: 553
Location: Home Office

joebuckeye wrote:
And just because you can generate a random 6 digit number doesn't mean it will all be unique either. There is no telling when you will get a previously generated number.

Which is more important? Being random or being unique?


But the OP is a "gud math student !! " so he should know that random is just that, and could be repeating ... or maybe I am misunderstanding what the OP means by "gud"
Back to top
View user's profile Send private message
kimbert
PostPosted: Thu Oct 24, 2013 6:45 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Quote:
maybe I am misunderstanding what the OP means
Yes, that's possible. The OP has explained the problem. We have suggested solutions. Let's leave it there.
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
vickas
PostPosted: Fri Oct 25, 2013 1:23 am    Post subject: Reply with quote

Centurion

Joined: 18 Aug 2013
Posts: 126

@ smdavies99
This solution works fine when i send a single message(contains multiple records).
RAND() is generating the same number for the second message(contains multiple records) as well.
Back to top
View user's profile Send private message
smdavies99
PostPosted: Fri Oct 25, 2013 1:29 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

vickas wrote:
@ smdavies99
This solution works fine when i send a single message(contains multiple records).
RAND() is generating the same number for the second message(contains multiple records) as well.


That's why you need to change the SEED every time.
http://en.wikipedia.org/wiki/Random_seed

Changing it TWICE for every output is IMHO pretty good. Remember that using six digits limits you to 999,999 different numbers.

You may have to call a java function that will allow you to change the seed.
_________________
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
fjb_saper
PostPosted: Fri Oct 25, 2013 4:55 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

And if you really need distinct numbers not so much as random, have you considered taking the last 6 chars of BROKERUUIDASCHAR ?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Esa
PostPosted: Fri Oct 25, 2013 5:06 am    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

fjb_saper wrote:
And if you really need distinct numbers not so much as random, have you considered taking the last 6 chars of BROKERUUIDASCHAR ?


They may be random enough, but not necessarily numbers and certainly not unique:
http://en.wikipedia.org/wiki/Universally_unique_identifier
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Generating Unique random number(INteger - 6 digits)
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.