CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2009
    Posts
    1

    Random Number Logic

    Hi,

    I have a question related to random number generation performance.

    We have a table in production on Oracle, with several millions of records(more than 100 Million).
    We have many EJB APIs deployed in weblogic which access this table. Things are fine from the performance point of view except one API, which has an internal logic of generating random number. The logic is as below:

    There is one crucial colums in this table called resource_value. Basically all APIs retrives this resource_value column based on several conditions.

    But for the API which needs to select this value randomly, we have a performance problem. The cuurent logic we are using is as below.

    1) Generate a 5 digit random number using Java rand() in the EJB, and then fires a query :

    select resource_value from table where resource_value like '%random number' and other where clause;

    if not found in above query we generate a 4 digit random number using Java rand() in the EJB, and then fires same query. We continue like this till 1 digit random number.

    We found this is not a good approach from performance point of view, since it uses %value in where clause and also because we have to do muliple query.

    Any ideas for a better performance logic?? Something can be done directly in Oracle???

    Ideas are much appreciated

  2. #2
    Join Date
    Apr 2007
    Posts
    425

    Re: Random Number Logic

    That is indeed a horrible way to do it.

    http://www.petefreitag.com/item/466.cfm

    Shows how to randomly retrieve a row from any database. Don't people use search engines anymore? That was the first hit by searching 'oracle select random'.

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Random Number Logic

    Quote Originally Posted by Deliverance View Post
    Don't people use search engines anymore?
    It's less hassle to come here and get someone else to do it and filter the results for you - and maybe they'll also fix your code too...

    One can think effectively only when one is willing to endure suspense and to undergo the trouble of searching...
    J. Dewey
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  4. #4
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: Random Number Logic

    Quote Originally Posted by dlorde View Post
    It's less hassle to come here and get someone else to do it and filter the results for you - and maybe they'll also fix your code too...
    Amen!
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

  5. #5
    Join Date
    May 2009
    Posts
    2,413

    Re: Random Number Logic

    Quote Originally Posted by Deliverance View Post
    Don't people use search engines anymore?
    People seek the personal touch; They visit this forum in the hope of having the advice of a real expert.

    If you're just one internet search ahead of the OP you can as well shut up. You're not the expert the OP came here for. You're just another besserwisser.
    Last edited by nuzzle; July 25th, 2009 at 07:03 PM.

  6. #6
    Join Date
    Apr 2007
    Posts
    425

    Re: Random Number Logic

    Quote Originally Posted by nuzzle View Post
    People seek the personal touch; They visit this forum in the hope of having the advice of a real expert.

    If you're just one internet search ahead of the OP you can as well shut up. You're not the expert the OP came here for. You're just another besserwisser.
    I'd love to hear your genius solution on retrieving a random row from a database that can't be done with the link I provided. He asked for ideas, I gave an idea in Oracle as requested.

    I really want you to show me (with proof) of a better approach for this solution. Otherwise, if you have nothing better to say, let's pull a line out of your vocabulary and shut your mouth if you have nothing good to say.

    I pity you, and find it quite sad that you have nothing better to do than hold a grudge against people who told you to shut you up for being an idiot. Good luck on growing that online ego!
    ------
    If you are satisfied with the responses, add to the user's rep!

  7. #7
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: Random Number Logic

    Quote Originally Posted by nuzzle View Post
    People seek the personal touch; They visit this forum in the hope of having the advice of a real expert...
    If someone wants a personal touch - use "s.e.x via the phone" service. We are just tired to answer the same questions hundreds of times when if googled just once you get all the answers in a sec without asking.
    Last edited by Xeel; July 27th, 2009 at 12:47 PM.
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured