8 digit random number
Hi,
Can any one help me to generate 8 digit unique random number, i have code some thing like
new Random().nextInt(100000000) + 1, but it generating 7 digit random number some times.
please give me the solution
thanks,
pvmk
pvmk wrote:
Is there any alternate logic to generate 8 digit random numberAs already implied
if you want random numbers in the range [10000000;99999999]
generate random numbers in the range [0;90000000[ and add 10000000
Similar Messages
-
I need to create a 17 digit random number to be used as a primary field in a database. They must all be unique. First, what is the best way to create a 17 digit random number, and second, how do I make sure it is unique?
I have a servlet that is parsing an email distribution
list and creating multiple users. For each user I
need to create a user id in the form of
"ID87890988909099900" that is unique. I do not know
how I would get Access to do this for me.Wow, you must have a lot of users. There aren't that many ants on earth.
Seriously, if the ID will always start with ID, then can't you just leave it off the key and add it when the ID is displayed? -
Generating N-digit random number??
Hi All,
I need to generate N-digit random number, anyone can help me?
Thx in advance b4...import java.util.*;
public class Try{
public static void main(String []args){
for(int i=0;i<100;i++){
System.out.println((int)(Math.random() * 10));
}Yes I saw the casting, no problem with it, but I did used it alot to generate me number between a range of 1 - 9
and if you want a range of 1 - 10, i just put a
1+(int)(Math.random() * 10) -
Hi All,
While running my application,I want to generate 3digit random number.
Is there any pre defined function.If not please suggest me some idea to get the same
Thanks in advanceSQL> EXEC DBMS_RANDOM.VALUE(100,999)
BEGIN DBMS_RANDOM.VALUE(100,999); END;
FOUT in regel 1:
.ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'VALUE'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
SQL> select dbms_random.value(100,999) from dual;
DBMS_RANDOM.VALUE(100,999)
338,5994241488838095483116070509848701
1 rij is geselecteerd.
SQL> select trunc(dbms_random.value(100,1000)) from dual;
TRUNC(DBMS_RANDOM.VALUE(100,1000))
918
1 rij is geselecteerd.Regards,
Rob. -
Hi guys,
i would like to have a text layer that changes it´s 4-digit number everytime it´s duplicated.
I found an expression that basically does that, but it also includes other values like "@" and "%".
s = "0" + Math.floor(random(10000));
while (s.length < 4) s = "0" + s;
The solution must be simple, I just really suck at expressions
Thanks for the help.
Cheers,
BjörnHi Dan,
i copied it to a new project now and it works as well (should have done that earlier, sry. Still weird ).
Now it generates a new numer every frame. Is there a way to keep the randomly genreated number over time?
Thanks for you help! -
I would like to generate 7 digit unique random number. I have it something like this :
Random generator = new Random();
generator.setSeed(System.currentTimeMillis());
//generates seven digit random number.
return generator.nextInt(9999999) + 999999;
But it generates 8 digit numbers sometimes. I am giving the Max limit in the braces and min limit after the "+" sign. Could anybody help me figure out what is wrong.This is not a horrible solution but an intelligent &
easy solution ;)Actually this would be the easy and intellegent solution to the problem "give a random 7 digit integer."
Random generator = new Random();
//generates seven digit random number.
return generator.nextInt(10000000);Though the orginal post does not specify this as part of the problem others have assumed (probably correctly) that in fact the poster wants a number between 1000000 and 9999999 (inclusive) which can easily be produced with the following modification to the above.
Random generator = new Random();
//generates seven digit random number.
return generator.nextInt(9000000) + 1000000;I am confused by your response. Are you saying the becasue the original question was asking why flawed code doesn't work, that makes your solution good? -
Generate Random Number By sequence
How to generate random 4 digit random number using sequence or any other method. Please suggest
4 digit random numbers can be obtained by:
SQL> SELECT TRUNC(DBMS_RANDOM.VALUE(1000,9999)) FROM DUAL;
TRUNC(DBMS_RANDOM.VALUE(1000,9999))
4002
SQL> /
TRUNC(DBMS_RANDOM.VALUE(1000,9999))
4748
SQL> /
TRUNC(DBMS_RANDOM.VALUE(1000,9999))
8328
SQL> /
TRUNC(DBMS_RANDOM.VALUE(1000,9999))
3667
SQL> /
TRUNC(DBMS_RANDOM.VALUE(1000,9999))
7464
SQL> /
TRUNC(DBMS_RANDOM.VALUE(1000,9999))
4893
SQL> /
TRUNC(DBMS_RANDOM.VALUE(1000,9999))
4961In mine case there is no repetition using Oracle 11.2.0.1 on Windows XP.
Regards
Girish Sharma -
Generate Random number-Dynamic.
Guys,
I'm looking for a pl\sql block to generate a 10 digit random number.
Could someone help me out?
Also, is there anyway to make it dynamic?..ie.If i pass 4 to the procedure\function, it should generate a 4 digit number..Thoughts please?
Regards,
BhagatPlease read about [url http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_random.htm#sthref4646]DBMS_RANDOM in the manual.
-
UDF to generate 4-Digit Positive Random Number
Hi,
I want to generate 4-Digit Positive Random Number in the Mapping for a field. Could anyone please provide Inputs or a UDF.
Regards,
VarunThis is the UDF I have Used
java.util.Random randomNumber;
String TransactionId = "" ;
randomNumber = new Random();
long longNumber = randomNumber.nextLong();
if (longNumber < 0)
longNumber = longNumber * (-1);
longNumber += 10000;
TransactionId = (String.valueOf(longNumber)).substring(0, 4);
return TransactionId ;
Thanks everyone for your Inputs -
Random number generation that sticks
Hello,
I would appreciate any help with the appropriate JavaScript to generate a random 8 digit number XXXX-XXXX on a form when the user starts to enter data. This number would need to be permanent so that it can be used as a tracking identifier later.
Thanks for looking.
DawsonIf you're using Oracle8i, you can use the new SAMPLE clause in the FROM clause of the SELECT statement to query a random sample from a single table. Otherwise, just write a simple random number generator in PL/SQL (see any good algorithm book under the topic "Psuedorandom number generator"). You need to understand a bit about statistics, if being "truly" random is important, to use these tools.
-
I have a need to generate random number keys for a DB2/6000 database. I am
expecting 10000 new entries per day to the table and due to design
constraints need to use an eight digit key. Also for design reasons the key
on the database is an integer attribute. I have looked at the built in
random number generator and it only produces a 2 byte number - I need 4.
Does anyone have a handy routine to produce larger random numbers?
TIA
/\/\ark /\/ichols
"Focus on the QUESTION, not on the ANSWER."
Lee Wei of Forte contributed a demo called RandomSort to Vol 1. of
the FShare CDROM. This has some generation code based on the Sedgewick LC
algorithm that you could probably adapt to your purposes. (e.g. I generated
8-digit integer values by multiplying Lee Wei's default for MAX by 10).
You can fiddle with the thing to change the minimum end of the range.
Robert Sedgewick's Algorithms in C (Addison Wesley 1990) is useful to
have for this sort of amusement.
If you don't have access to the FShare 1 CDROM I could send you the
pex file.
Regards,
Stephen Porterfield
LongsThere is an excellent book written by Knuth about
Randon Numbers generator algorithms...
"The Art of Computer Programming, Donald E. Knuth" -- Vol 2, pp 1-170
Have a look at these other books if you want more info:
"Monte Carlo Simulations: Hidden Errors from 'Good' Random Number
Generators",Physical Review Letters, Alan M.
Ferrenberg, D. P. Landau, and Y. Joanna Wong, Vol 69 No. 23, Dec 7 1992
"Monkey Tests for Random Number Generators",Computers Mathematics
Applications, G Marsaglia, and A Zaman, Vol 26, No
9 1993, pp 1-10.
A Current View of Random Number Generators", Computer Science and
Statistics: 16th Sympossium on Interface, Elsevier,
1985.
Hope this helps,
--francois
From: Vasas, Marty
Sent: Thursday, April 10, 1997 8:31 AM
To: mark h. nichols; forte users
Subject: RE: Random number keys
16
Let's write 2 as twoToThe16th
If there's nothing built-in to do the job, write a method for the
following algorithm:
generate 2 two-byte integers, A and B, from the built-in random number
generator.
return A * twoToThe16th + B
From: mark h. nichols
Sent: Thursday, April 10, 1997 10:10 AM
To: forte users
Cc: vasasm; murthis
Subject: Random number keys
MCI Mail date/time: Thu Apr 10, 1997 7:25 am EST
Source date/time: Thu, 10 Apr 1997 06:37:17 -0500
I have a need to generate random number keys for a DB2/6000 database. I
am
expecting 10000 new entries per day to the table and due to design
constraints need to use an eight digit key. Also for design reasons the
key
on the database is an integer attribute. I have looked at the built in
random number generator and it only produces a 2 byte number - I need 4.
Does anyone have a handy routine to produce larger random numbers?
TIA
/\/\ark /\/ichols
"Focus on the QUESTION, not on the ANSWER." -
I have a need to generate random number keys for a DB2/6000 database. I am
expecting 10000 new entries per day to the table and due to design
constraints need to use an eight digit key. Also for design reasons the key
on the database is an integer attribute. I have looked at the built in
random number generator and it only produces a 2 byte number - I need 4.
Does anyone have a handy routine to produce larger random numbers?
TIA
/\/\ark /\/ichols
"Focus on the QUESTION, not on the ANSWER."There is an excellent book written by Knuth about
Randon Numbers generator algorithms...
"The Art of Computer Programming, Donald E. Knuth" -- Vol 2, pp 1-170
Have a look at these other books if you want more info:
"Monte Carlo Simulations: Hidden Errors from 'Good' Random Number
Generators",Physical Review Letters, Alan M.
Ferrenberg, D. P. Landau, and Y. Joanna Wong, Vol 69 No. 23, Dec 7 1992
"Monkey Tests for Random Number Generators",Computers Mathematics
Applications, G Marsaglia, and A Zaman, Vol 26, No
9 1993, pp 1-10.
A Current View of Random Number Generators", Computer Science and
Statistics: 16th Sympossium on Interface, Elsevier,
1985.
Hope this helps,
--francois
From: Vasas, Marty
Sent: Thursday, April 10, 1997 8:31 AM
To: mark h. nichols; forte users
Subject: RE: Random number keys
16
Let's write 2 as twoToThe16th
If there's nothing built-in to do the job, write a method for the
following algorithm:
generate 2 two-byte integers, A and B, from the built-in random number
generator.
return A * twoToThe16th + B
From: mark h. nichols
Sent: Thursday, April 10, 1997 10:10 AM
To: forte users
Cc: vasasm; murthis
Subject: Random number keys
MCI Mail date/time: Thu Apr 10, 1997 7:25 am EST
Source date/time: Thu, 10 Apr 1997 06:37:17 -0500
I have a need to generate random number keys for a DB2/6000 database. I
am
expecting 10000 new entries per day to the table and due to design
constraints need to use an eight digit key. Also for design reasons the
key
on the database is an integer attribute. I have looked at the built in
random number generator and it only produces a 2 byte number - I need 4.
Does anyone have a handy routine to produce larger random numbers?
TIA
/\/\ark /\/ichols
"Focus on the QUESTION, not on the ANSWER." -
AppleScript Random Number Question.
I know there are several "guess a random number" AppleScript examples on the web, but I tried writing my own to see if I could pull it off. Works pretty good except for one bug. If the random number is lower than 10 (single digit) and I guess a number 10 or higher, my script comes back saying my guess is too small! Everything in my code looks reasonable to me, but obviously I'm overlooking something! Here's my code:
set rnd to (random number from 1 to 20)
set rnd to rnd as string
set num to 5
repeat 5 times
if num = 1 then
set anw to text returned of (display dialog "You have only 1 guess left!
Pick a number from 1 to 10." default answer "" buttons {"OK"} default button 1)
else
set anw to text returned of (display dialog "You have " & num & " guesses left!
Pick a number from 1 to 20." default answer "" buttons {"OK"} default button 1)
end if
if anw < rnd then
display dialog "Too Small!" buttons {"OK"} default button 1
else
if anw > rnd then
display dialog "Too Big!" buttons {"OK"} default button 1
else
if anw = rnd then
display dialog "Correct!" buttons {"OK"} default button 1
return
end if
end if
end if
set num to num - 1
end repeat
display dialog "You have run out of guesses!
The number was " & rnd & "." buttons {"OK"} default button 1you need to convert the variable anw to an integer, otherwise your script will compare anw to rnd as text strings (and text strings beginning with 1 are always small). add the following code before you do your comparisons:
set anw to anw as integer
also, your script will be cleaner if you use the 'else' command in your if statement:
if anw < rnd then
display dialog "Too Small!" buttons {"OK"} default button 1
else if anw > rnd then
display dialog "Too Big!" buttons {"OK"} default button 1
else
display dialog "Correct!" buttons {"OK"} default button 1
return
end if -
How to generate a random number with at least 6 digits?
Hi all,
All is in the question. :-)
I would like to generate a random number but the function "random
number" in Labview isn't accurate enough.
Do you know an algorithm to generate a random number of 6 or more
digit?
Thanks,
PFHi PF,
It's simple. Use 2 random number functions in the same process. Now you
should have 2 distinct random numbers that have the same accuracy. Let's say
LV gives accuracy up to the thousandth (0.XXX), now if you divide one number
by 1000 and then add to the other number you should then have something like
0.XXXXXX. Actually, LV random number function can give up to about 17 digits
(decimal). If you are looking for more digits (>17 digits), the idea above
may not work, then the last thing you may want try is to generate two or
three random numbers then convert all these decimal numbers to fractional
strings chop off the 0 and dot then concatinate them together. After all
it's still a random number. How many digits do you want to get? Make sure
the indicators acce
pt that many digits?
Good luck
Louis.
P-F wrote in message
news:[email protected]..
> Hi all,
>
> All is in the question. :-)
>
> I would like to generate a random number but the function "random
> number" in Labview isn't accurate enough.
>
> Do you know an algorithm to generate a random number of 6 or more
> digit?
>
> Thanks,
>
> PF -
A simple question on random number generation?
Hi,
This is a rather simple question and shows my newbieness quite blatantly!
I'm trying to generate a random number in a part of a test I have.
So, I have a little method which looks like this:
public int getRandomNumber(int number){
Random random = new Random(number);
return random.nextInt(number);
}And in my code I do int random = getRandomNumber(blah)...where blah is always the same number.
My problem is it always returns the same number. What am I missing here. I was under the impression that nextint(int n) was supposed to generate the number randomly!! Obviously I'm doing something wrong or not using the correct thing. Someone please point out my stupidity and point me in the right direction? TaI think the idea is that Random will generate the same pseudo-random sequence over and over if you don't supply a seed value. (The better to debug with, my dear.) When you're ready to put an app into production, the seed value should be the current system time in milliseconds to guarantee a new sequence with each run.
Do indeed move Random outside the loop. Think of it like a number factory - instantiate it once and let it pump out the random values for you as needed.
Maybe you are looking for
-
I updated to IOS 5 tonight on my ipod touch 4th gen and now it won't restore. I can't get it to restore from a backup either. It either says "iTunes could not restore the iPod "____" because the backup session failed or i get error -50. It appears
-
IPhoto 9.1.5 spinning wheel importing photos from SD-Card
Hi, On the Mac Mini (Intel Core Duo 1.66 GhZ) with Snow Leopard 10.6.8 and iPhoto 9.1.5, when inserting a SD-Card from a camera, through a USB Card Reader, iPhoto starts and switches to the import assistant, but won't ever display the content of the
-
Using find my iPhone with two phones
My wife and i share the same apple id. I have a mobile me account and she doesn't, is there any way for her to activate find my iphone on her phone with my apple id and not pull up my mail on her phone as a result?
-
Groupware Integration in CRM server
Hi , We try to develop a Groupware integration at CRM - SERVER and EXCHNANGE -SERVER . Our SAP - CRM runs on LINUX Platform . Kindly send the step by step Groupware Integration . Regrards
-
Acrobat Pro form getting MAPI spooler error
I have a form created in Acrobat Pro. The users are using Reader 9.3.1. When the user clicks the Submit button, they get a MAPI Spooler error. For some Windows Services closes Reader. Any thoughts on what is causing this and how to fix? Thanks, MDawn