Find fields & stores near you!
Find fields and stores
Zipcode
PbNation News
PbNation News
Community Focus
Community Focus

Reply
 
Thread Tools
Old 05-11-2009, 06:44 AM #1
pb_freak9666
ST:T's Resident Otaku
 
pb_freak9666's Avatar
 
Join Date: Nov 2007
Location: A cave with wifi.
Annual Supporting Member
pb_freak9666 donated to help Peyton Trent
pb_freak9666 helped look for balloons
pb_freak9666 is reppin' sidebar 4 life
pb_freak9666 has perfected Level 1 in PbNation Pursuit
pb_freak9666 has achieved Level 2 in PbNation Pursuit
pb_freak9666 has perfected Level 2 in PbNation Pursuit
pb_freak9666 has achieved Level 3 in PbNation Pursuit
Need some JAVA programming help

So I'm taking a JAVA programming class, but I'm not too good with it. We needed to come up with a random number generator that won't come up with the same number twice, and it can use up to 3 digits. But this is a close as I could get:
Code:
import java.util.Random; /** Generate 10 random integers in the range 0..99. */ public final class RandomInteger { public static final void main(String... aArgs){ log("Generating 10 random integers in range 0..99."); //note a single Random object is reused here Random randomGenerator = new Random(); for (int idx = 1; idx <= 10; ++idx){ int randomInt = randomGenerator.nextInt(100); log("Generated : " + randomInt); } log("Done."); } private static void log(String aMessage){ System.out.println(aMessage); } }
Anyone have have any suggestions on how I can tweak this?

EDIT: I'm also using the freeware bluejay to program in JAVA.
__________________
xfire-stix9693
Steam - slygathore
PSN - SLYGATHOR
XBL - S1YGATHOR - (that's a 1 not an L)
R.I.P Christian James Koehler, I'll miss you buddy.
Building a computer is like playing with Legos, the pieces only fit one way.
"If ya gots more feelin's to express, go into the kitchen and bake yourself a bunt cake."
My Minecraft Server: craftserve.dyndns.org

Last edited by pb_freak9666 : 05-11-2009 at 06:51 AM.
pb_freak9666 is offline   Reply With Quote
Old 05-11-2009, 10:54 AM #2
fireisgood4u
UNDERSTAND UNDERSTAND
 
fireisgood4u's Avatar
 
Join Date: May 2004
Location: so*on
Red face

Nuclear decay.

Geiger counter and a household smoke detector.
__________________
______________
fireisgood4u is offline   Reply With Quote
Old 05-11-2009, 11:07 AM #3
pb_freak9666
ST:T's Resident Otaku
 
pb_freak9666's Avatar
 
Join Date: Nov 2007
Location: A cave with wifi.
Annual Supporting Member
pb_freak9666 donated to help Peyton Trent
pb_freak9666 helped look for balloons
pb_freak9666 is reppin' sidebar 4 life
pb_freak9666 has perfected Level 1 in PbNation Pursuit
pb_freak9666 has achieved Level 2 in PbNation Pursuit
pb_freak9666 has perfected Level 2 in PbNation Pursuit
pb_freak9666 has achieved Level 3 in PbNation Pursuit
What?
__________________
xfire-stix9693
Steam - slygathore
PSN - SLYGATHOR
XBL - S1YGATHOR - (that's a 1 not an L)
R.I.P Christian James Koehler, I'll miss you buddy.
Building a computer is like playing with Legos, the pieces only fit one way.
"If ya gots more feelin's to express, go into the kitchen and bake yourself a bunt cake."
My Minecraft Server: craftserve.dyndns.org
pb_freak9666 is offline   Reply With Quote
Old 05-11-2009, 12:23 PM #4
fireisgood4u
UNDERSTAND UNDERSTAND
 
fireisgood4u's Avatar
 
Join Date: May 2004
Location: so*on
Red face

When you use a language's internal random number generator it's 'pseudorandom.' It's generated by software it is not truly random.

Through external hardware you can achieve truly random numbers.

Nuclear decay is random and if you can measure it voila. So get crackin on that nuclear reactor.

Where are you stuck at? I don't know Java but I can provide C pseudocode if that'd help give you ideas.
__________________
______________
fireisgood4u is offline   Reply With Quote
Old 05-11-2009, 12:29 PM #5
pb_freak9666
ST:T's Resident Otaku
 
pb_freak9666's Avatar
 
Join Date: Nov 2007
Location: A cave with wifi.
Annual Supporting Member
pb_freak9666 donated to help Peyton Trent
pb_freak9666 helped look for balloons
pb_freak9666 is reppin' sidebar 4 life
pb_freak9666 has perfected Level 1 in PbNation Pursuit
pb_freak9666 has achieved Level 2 in PbNation Pursuit
pb_freak9666 has perfected Level 2 in PbNation Pursuit
pb_freak9666 has achieved Level 3 in PbNation Pursuit
What I've wrote so far, is just for a single digit, I need it to be randomized up to 3. And so it can't use the same number sequence twice. Which I have no idea how to do.
__________________
xfire-stix9693
Steam - slygathore
PSN - SLYGATHOR
XBL - S1YGATHOR - (that's a 1 not an L)
R.I.P Christian James Koehler, I'll miss you buddy.
Building a computer is like playing with Legos, the pieces only fit one way.
"If ya gots more feelin's to express, go into the kitchen and bake yourself a bunt cake."
My Minecraft Server: craftserve.dyndns.org
pb_freak9666 is offline   Reply With Quote
Old 05-11-2009, 02:11 PM #6
boomslang
lo-fi
 
boomslang's Avatar
 
Join Date: Jul 2003
 has been a member for 10 years
Add generated numbers to a queue, look through the queue to determine if you've already generated that number?
__________________
Shoot the ****: irc.oftc.net #doublethink | dodgyaim
boomslang is offline   Reply With Quote
Old 05-11-2009, 02:40 PM #7
pb_freak9666
ST:T's Resident Otaku
 
pb_freak9666's Avatar
 
Join Date: Nov 2007
Location: A cave with wifi.
Annual Supporting Member
pb_freak9666 donated to help Peyton Trent
pb_freak9666 helped look for balloons
pb_freak9666 is reppin' sidebar 4 life
pb_freak9666 has perfected Level 1 in PbNation Pursuit
pb_freak9666 has achieved Level 2 in PbNation Pursuit
pb_freak9666 has perfected Level 2 in PbNation Pursuit
pb_freak9666 has achieved Level 3 in PbNation Pursuit
That's the thing, this is as much as I know...
__________________
xfire-stix9693
Steam - slygathore
PSN - SLYGATHOR
XBL - S1YGATHOR - (that's a 1 not an L)
R.I.P Christian James Koehler, I'll miss you buddy.
Building a computer is like playing with Legos, the pieces only fit one way.
"If ya gots more feelin's to express, go into the kitchen and bake yourself a bunt cake."
My Minecraft Server: craftserve.dyndns.org
pb_freak9666 is offline   Reply With Quote
Old 05-11-2009, 03:10 PM #8
PbGoods
Need to pay student loans
 
Join Date: Aug 2007
Location: NJ
PbGoods is reppin' sidebar 4 life
I was working on something similar but in C++.

Basically here is the pseudocode of the program:

Generate random numbers.
Store the random numbers into an array or however you want to store them.
Have a temp variable that take the value of one of the random numbers.
Check to see if this number exists as a duplicate
If number is not a duplicate, continue to check the rest of the numbers.
If number is a duplicate reassign that variable with a new value.

Hope that makes sense.

Edit: You can also check Google for "Java: non repeating random numbers"
PbGoods is offline   Reply With Quote
Old 05-11-2009, 06:05 PM #9
pb_freak9666
ST:T's Resident Otaku
 
pb_freak9666's Avatar
 
Join Date: Nov 2007
Location: A cave with wifi.
Annual Supporting Member
pb_freak9666 donated to help Peyton Trent
pb_freak9666 helped look for balloons
pb_freak9666 is reppin' sidebar 4 life
pb_freak9666 has perfected Level 1 in PbNation Pursuit
pb_freak9666 has achieved Level 2 in PbNation Pursuit
pb_freak9666 has perfected Level 2 in PbNation Pursuit
pb_freak9666 has achieved Level 3 in PbNation Pursuit
Thanks for the help guys. I got all of it written, with the exeption of an GUI, I don't know how to create a form with just a textbox and button in BlueJ.
__________________
xfire-stix9693
Steam - slygathore
PSN - SLYGATHOR
XBL - S1YGATHOR - (that's a 1 not an L)
R.I.P Christian James Koehler, I'll miss you buddy.
Building a computer is like playing with Legos, the pieces only fit one way.
"If ya gots more feelin's to express, go into the kitchen and bake yourself a bunt cake."
My Minecraft Server: craftserve.dyndns.org
pb_freak9666 is offline   Reply With Quote
Old 05-11-2009, 09:54 PM #10
Darth Bagel
read. comprehend. post.
 
Darth Bagel's Avatar
 
Join Date: May 2001
Location: Rochester, NY
Darth Bagel is a Supporting Member
 has been a member for 10 years
It can't do the same *number* twice or it can't do the same *sequence* twice? The two are very different. If it's number, you'll need to use the queue. If it's sequence, just seed it with the current time.
__________________
the door is open
Darth Bagel is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
Forum Jump