Results 1 to 14 of 14
 03232011, 07:20 PM #1Member
 Join Date
 Mar 2011
 Posts
 7
 Rep Power
 0
 03232011, 08:37 PM #2Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,692
 Rep Power
 13
What do you mean "with 5 ciphers"?
(Dictionary.com tells me that "cipher" means "zero" and "a secret method of writing" amongst other things.)
A random int with 5 zeros in its decimal representation? Chaining together 5 encryption algorithms so that the output for any input is random? Something else?
 03232011, 10:10 PM #3Member
 Join Date
 Mar 2011
 Posts
 7
 Rep Power
 0
Sorry for my english, I meant "cypher" or "digit":
figure
number
digit
cipher
numeral
quantity
cypher ...
For example "45399" (5 cyphers). How to generate a random int with an specific number of cyphers? Thank you again
 03232011, 11:10 PM #4
Math.random() produces a random number between [0.0 and 1.0), so you would simply need to translate that range to be from 0 to 99999 (if you want to include things like 00012) or from 10000 to 99999 (if you want no leading zeroes).
Something like... (int)(Math.random() * (upper  lower) + lower)
 03232011, 11:22 PM #5
You can also use the Random class.
 03232011, 11:40 PM #6Member
 Join Date
 Mar 2011
 Posts
 7
 Rep Power
 0
Aha, ok, but I have also another problem... I don't know the exactly the number of cyphers that the random will have; I mean, in the code that I'm making, when you run the program it ask you how many cyphers do you want your random number to have? This also I don't know how to make it... But I have an idea:
You get the int with the # of cyphers, then convert to string and you can know his length. Now you have his length, and now you create vectors with this length (2 vectors) and get one of them filled with 1....0 and 9....9. But how you use this vectors now?
Thank you very much guys! ;)
 03232011, 11:44 PM #7
Yes that would probably be simplest way unless some math genius can provide you with an expression.
Now you have his length, and now you create vectors with this length (2 vectors) and get one of them filled with 1....0 and 9....9. But how you use this vectors now?
 03242011, 01:02 AM #8Member
 Join Date
 Mar 2011
 Posts
 7
 Rep Power
 0
Sorry, I will put it in the simple way... I wanna make a program that ask you "Do you want make a random number? If yes, how many cyphers should it have?" You enter the # of cyphers and you get the random number, you follow me? :)
Thanks!
 03242011, 01:12 AM #9
I understand all that but was has 2 vectors got to do with it?
 03242011, 01:30 AM #10Member
 Join Date
 Mar 2011
 Posts
 7
 Rep Power
 0
Forget about it, it was just an idea ;P I thought that maybe creating vectors with length = number of cyphers, filling one of them with the min value and the other one with the max value (one cypher per position in the vector), and try to convert it to the normal number but...I don't know how to do it
 03242011, 01:39 AM #11
Well you could use a single array/Vector/List with a length of N. Then generate N single digits random numbers 09 and add to the list. Then convert the end result to an int but you would have to check if the first digit was zero.
 03242011, 01:22 PM #12Member
 Join Date
 Mar 2011
 Posts
 7
 Rep Power
 0
Yes thats a good idea, but how I convert the list into an "int"?
 03242011, 06:41 PM #13Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,692
 Rep Power
 13
how I convert the list into an "int"?
Use the fact that , eg, 7268=10*(10*(10*7+2)+6)+8. The number 7268 is formed from the list 7, 2, 6, 8 by repeatedly multiplying by 10 and adding the next list item.

Consider the 6 digit random numbers. They run from 100000 to 999999. You could start with a random number from zero (inclusive) to 900000 (exclusive) then add 100000.
The general case for other values of "n" is similar. Find the upper limit by multiplying 9 by 10 (n1) times etc.
 03252011, 01:34 AM #14Member
 Join Date
 Mar 2011
 Posts
 7
 Rep Power
 0
Similar Threads

Can I get random.util not to generate the same number twice
By lilleza87 in forum New To JavaReplies: 3Last Post: 10242010, 10:24 PM 
[SOLVED] How to generate a random number from chisquare
By aeo3 in forum AWT / SwingReplies: 3Last Post: 04162009, 01:42 AM 
Trying to Generate Random number
By PeterFeng in forum New To JavaReplies: 10Last Post: 01142009, 09:37 AM 
Generate a random number
By romina in forum New To JavaReplies: 1Last Post: 08072007, 05:23 AM 
How to generate random number in java
By fernando in forum New To JavaReplies: 1Last Post: 08012007, 07:32 PM
Bookmarks