Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-15-2007, 05:03 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
random numbers without using java funtions
i need a formula to generate 100 random numbers 1-20

any suggestions?

remember, no functions

thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-15-2007, 05:49 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
int n = (int)(1 + 20*Math.random());
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-15-2007, 05:50 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
we cannot use the Math.random function
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-15-2007, 05:53 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
this is some code it - Each number needs to be generated.
Each number should be generated at least 300 times of the 10,000.


Code:
public class Random_Gen { int min; //minimum number that can be generated. int max; //maximum number that can be generated. int value; public Random_Gen(int n, int m) { max = m; //code goes in this class min = n; } public int getRandom() { return value; } } public static void main(String[] args) { int min = 1; // smallest number that can be generated int max = 20; // largest number that can be generated Random_Gen rg = new Random_Gen(min, max); int num; int[] frequency = new int[max]; for (int x = 0; x < 10000; x++) { num = rg.getRandom(); System.out.println(num); for (int index = 0; index < max; index ++) //determines frequency { if (num == index + 1) frequency[index]++; } } for (int index = 0; index < max; index ++) // displays frequency { System.out.println(""+(index+1) + " = " + frequency[index]); } }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-15-2007, 06:29 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Can you use the java.util.Random class?
Edit: random numbers without using java funtions
aha - no java. Check the next method in the Random class for some clues.

Last edited by hardwired : 11-15-2007 at 07:01 AM. Reason: read the title
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-16-2007, 12:45 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
i dont understand
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-16-2007, 01:01 AM
Member
 
Join Date: Nov 2007
Posts: 8
lk9865 is on a distinguished road
Quote:
Originally Posted by hardwired View Post
Can you use the java.util.Random class?
Edit: random numbers without using java funtions
aha - no java. Check the next method in the Random class for some clues.
carlos,
just like hardwired said there is another java class called Random you can upload before your programs you try something like this
Code:
java.util.Random; public class RandomProject{ public staid void main(strings[] args){ Random generator = new Random(); //give a object name for the class for(int i=0; i<=100; i++){ int randomNumbers = generator.nextInt(20);//will generate numbers from1-20 System.out.println(randomNumbers); } } }
there you go you have now generated 100 random numbers between 1 and 20 hope this helps
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-16-2007, 05:39 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
we cannot use any java functions
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 11-16-2007, 12:13 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
Quote:
we cannot use any java functions
Then try searching "generating random numbers" on Google and try to implement your own random number generator.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Computing prime numbers in Java Java Tip java.lang 0 04-12-2008 10:39 PM
random numbers without random class` carlos123 New To Java 4 01-18-2008 12:44 AM
random numbers carlos123 New To Java 1 12-22-2007 04:56 AM
generating random numbers in a 5x5 array. acidacid New To Java 3 08-14-2007 05:44 AM
How to generate random number in java fernando New To Java 1 08-01-2007 09:32 PM


All times are GMT +3. The time now is 09:28 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org