Results 1 to 12 of 12
Thread: Random Password
- 07-11-2011, 09:24 AM #1
- 07-11-2011, 09:30 AM #2
Whoa buddy, getting pretty wild with that text there.
There are plenty of ways you can do it. The easiest would be to make an array containing all of these characters and then picking a random index to make it. If you use the Random class, you will get a different combo every time. You could probably accomplish this with ~10 lines of code.- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 07-11-2011, 09:39 AM #3
Can you show me a simple code about random function. I don't how to generate different password everytime...
- 07-11-2011, 09:48 AM #4
Google is a good source to figure out how to use something. There are thousands of examples of how to use different parts of Java on the web.
Read these articles on the Random class. It will teach you how to use it.
Java Random Numbers
Java Practices -> Generate random numbers- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 07-11-2011, 04:13 PM #5
That impiles that you keep a record of what has been generated in the past so you can reject a newly generated one if it has already been generated and keep going back and getting another one until it is unique.how to generate different password everytime
- 07-11-2011, 05:32 PM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
If you know how to generate a password once, it shouldn't be too hard to keep track of previous password generations. It may be a little different(not much) if you want different executions to not generate the same passwords. Try building it incrementally, first generate a password, then figure out how to track previous passwords, then find out how to save the passwords. A file would probably be the easiest.
- 07-11-2011, 07:14 PM #7
Member
- Join Date
- Jul 2011
- Posts
- 43
- Rep Power
- 0
Java Code:import java.util.*; class Pass { public static void main(String ar[]) { Random r= new Random(); String arr[]={"1","2","3","4","5","6","7","8","9","0","a","b","c"}; int p; for (int i=1;i<=8;i++) { p=r.nextInt(13); System.out.print(arr[p]); } } }
- 07-12-2011, 06:22 AM #8
This is spoon feeding, not only that but your program isn't very flexible. You also hard coded your random integer instead of using arr.length making the use limited and if the variables ever change, you have to go and change the number of possible choices.
The method you decided to take is also inefficient, as instead of using an integer and storing your random choice to it you should have done something like System.out.print(arr[r.nextInt(arr.length)]);
Thanks to your spoon feeding, the OP no longer has to think for himself and is probably passing your code off as his homework. Good Job.- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 07-12-2011, 06:50 AM #9
Member
- Join Date
- Jul 2011
- Posts
- 43
- Rep Power
- 0
thanks for pointing out my mistakes
.gif)
i am sorry for spoon feeding i am also new to java.i was just trying to solve the problem so that i could also get to learn somethingThanks to your spoon feeding, the OP no longer has to think for himself and is probably passing your code off as his homework. Good Job.
- 07-12-2011, 07:00 AM #10
There is no problem with that but part of the learning process doesn't involve you posting your solution on the net for others to cheat from.i am sorry for spoon feeding i am also new to java.i was just trying to solve the problem so that i could also get to learn something
- 07-12-2011, 09:27 AM #11
Senior Member
- Join Date
- Nov 2010
- Posts
- 150
- Rep Power
- 3
Boom roasted! Just kidding!
- 07-12-2011, 12:27 PM #12
Exactly, if you are trying to solve problems that other people have for learning purposes there is no shame in trying to make the program. However, posting the solution doesn't help the user. If you manage to figure out how to solve the problem, that means you know roughly what the OP should do so if he has any more problems with his code you are better equipped to give him suggestions.
- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
Similar Threads
-
how i use the random class to random the cards i have
By yanipao in forum New To JavaReplies: 14Last Post: 10-19-2009, 10:57 AM -
How do I generate random numbers in a certain range using the random class?
By frasifrasi in forum New To JavaReplies: 8Last Post: 04-19-2009, 05:50 PM -
how to check password for 3 times enterd wrong password
By sk.mahaboobbhasha@gmail.c in forum New To JavaReplies: 2Last Post: 11-14-2008, 07:53 PM -
how to check password for 3 times enterd wrong password
By sk.mahaboobbhasha@gmail.c in forum Java ServletReplies: 0Last Post: 11-14-2008, 01:22 PM -
How to check password of a jsp/html with the password of Database(mysql) #1
By sk.mahaboobbhasha@gmail.c in forum Java ServletReplies: 2Last Post: 11-14-2008, 01:11 PM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks