Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Random numbers
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
richcash




PostPosted: Wed Oct 25, 2006 4:45 pm   Post subject: (No subject)

I see what you mean about that, but if we had the time to run it 'megagazillions' of times, wouldn't my code produce twice as many 10.0's as your code? This is all abstract and very impractical; for the person implementing this, just exclude 10.0 and multiply by 10 Wink.
Sponsor
Sponsor
Sponsor
sponsor
Cheese_slice




PostPosted: Mon Sep 29, 2008 4:21 pm   Post subject: RE:Random numbers

I'm trying to write a simple program that give out a random number in a range, but it doesn't seem to want to work properly.... (The range is from 20-50)



import java.util.Random;

class randomNum {

public static void main (String [] args) {

Random r = new Random();

int highNum, lowNum;

highNum = 50;

lowNum = 20;

System.out.println(r.nextInt((highNum - lowNum + 1) + lowNum)); }

}

I got my formula from a text book, but it doesn't explain further. (Somewhere the is a logic error, I just can't find it)
wtd




PostPosted: Mon Sep 29, 2008 4:40 pm   Post subject: RE:Random numbers

Holy necro post Batman!
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 18 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: