Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 01-08-2008, 08:22 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
random generation
ok guys, i need to generate 10,000 random numbers less then 20, i want my program to take the seconds from the clock, divide it by 3, and then put it through a formula to then create 10,000 psuedo-random numbers, under 20, any help guys. thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-08-2008, 08:31 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 251
roots is on a distinguished road
For generation .. javarng - Google Code
and Follow wikipedia as well ..
under 20 is not a problem just mod by 20..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-08-2008, 08:52 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
i forgot to mention i cannot use the java.random class. LOL
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-08-2008, 08:55 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 251
roots is on a distinguished road
Exactly .. Above link is similar implementation .. Review how they have done and write yours ..

Art of Computer Programming by Donald E. Knuth is a good book to have for this ..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-08-2008, 09:03 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
im not suppose to use those algorithms, its just basicly, i take the seconds, and divide it by 3, and put it through a formula 10,000 times, and it should be kind of random, like it doesnt have to be completly random, its just a test on how random we can make a program without using those random elements. comprende? any suggestions on the formula would help.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-08-2008, 09:15 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 251
roots is on a distinguished road
nanoTime() when bounded by limit of 20 itself gives pretty different results. You can mess it up stretching it up with arithmetic operation of your choice. nada . I am not talking about taking the algorithm .. you need to write yours .. But you will get basic idea from existing random number generator algorithm ..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-08-2008, 09:19 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
im sorry, im new to java , i dont know what nanotime is
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 01-08-2008, 09:24 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 251
roots is on a distinguished road
System.nanoTime() gives time in nanoseconds ...
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 01-08-2008, 09:25 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
whats an existing random number generator algorithm
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 01-08-2008, 09:26 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
and how would i bound nano seconds to 20
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 01-09-2008, 04:43 AM
Member
 
Join Date: Nov 2007
Posts: 38
carlos123 is on a distinguished road
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
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
EJB generation with xdoclet tags gugas Enterprise JavaBeans 0 02-18-2008 02:07 PM
random numbers without random class` carlos123 New To Java 4 01-17-2008 11:44 PM
random numbers carlos123 New To Java 1 12-22-2007 03:56 AM
String generation codingisfun22 Advanced Java 3 12-03-2007 06:43 AM
Math.Random Java Tip Java Tips 0 11-23-2007 03:09 PM


All times are GMT +3. The time now is 10:36 AM.


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