-
generate random number
I have to generate random number from 1 to 40. I used DBMS_RANDOM.value.
"
declare
num number:=0;
begin
num:=round(dbms_random.value(1,10));
dbms_output.put_line('Number: '||num);
end;
"
when i execute this block, it gives me random number but it is repeating some numbers. For ex 9 is repeating thrice.
i want that the randome number should exclude the number which it has generated earlier. it should not repeat it.
-
1 to 40 is a pretty small range for random number generation - I would expect lots of "duplicates".
Having said that, you can always wrap up dbms_random block into a loop where you discard the numbers you don't like and try again.
oops... that is going to take out some randomblish of dbms_random process, isn't it?
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
random numbers
bhai 1-to 40 was just an example.anyhow i wanted if any built in function is available with DBMS_RANDOM package to actually givr only unique random numbers....
is there any ?
reply awaited.
-
if you want unique why not use a sequence and just get nextval?
-
generate random numbers
i want unique random numbers..anywaz it seems like no such inbuilt function is avbl with DBMS_RANDOM..i think my logic of putting dbms_random inside a loop & exluding the one which is already generated will do....i just wanted a replacement for my logic with some inbuilt stuff.
-
Originally Posted by binoyshil
i think my logic of putting dbms_random inside a loop & exluding the one which is already generated will do.
"my logic"? ... you are fast at taking credit for whatever happens around, aren't you? LMAO
Last edited by PAVB; 12-07-2009 at 08:30 AM.
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
Originally Posted by binoyshil
i want unique random numbers..anywaz it seems like no such inbuilt function is avbl with DBMS_RANDOM..i think my logic of putting dbms_random inside a loop & exluding the one which is already generated will do....i just wanted a replacement for my logic with some inbuilt stuff.
unique and random - its impossible to have both becuase you are taking away the randomness of it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|