Connecting Tech Pros Worldwide Help | Site Map

Can someone help me with Nim?

Newbie
 
Join Date: Oct 2009
Posts: 2
#1: 4 Weeks Ago
I have to write a program of nim that the human plays against a computer player. I have to generate a random integer between 10 and 100 to denote the initial size of the pile. I have to generate a random integer between 0 and 1 to decide who takes the first turn. I have to generate a random integer between 0 and 1 to decide if the computer is smart or stupid.

Can someone please tell me how to generate a random integer?
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: 4 Weeks Ago

re: Can someone help me with Nim?


Please at least attempt the problem before asking for help. The experts here are more than happy to give you a hand with your problems but you have to do your part to at least research/learn the basics.

If you had googled your question before asking you would have come across a website with the following example that generates random numbers (first link I found):

Expand|Select|Wrap|Line Numbers
  1. import java.util.Random;
  2.  
  3. /** Generate 10 random integers in the range 0..99. */
  4. public final class RandomInteger {
  5.  
  6.   public static final void main(String... aArgs){
  7.     log("Generating 10 random integers in range 0..99.");
  8.  
  9.     //note a single Random object is reused here
  10.     Random randomGenerator = new Random();
  11.     for (int idx = 1; idx <= 10; ++idx){
  12.       int randomInt = randomGenerator.nextInt(100);
  13.       log("Generated : " + randomInt);
  14.     }
  15.  
  16.     log("Done.");
  17.   }
  18.  
  19.   private static void log(String aMessage){
  20.     System.out.println(aMessage);
  21.   }
  22. }
Newbie
 
Join Date: Oct 2009
Posts: 2
#3: 4 Weeks Ago

re: Can someone help me with Nim?


I did google the question and I got alot of different answers, none like the one above. I even tried some of them and it did not work. I hope yours works. Why are you such a jerk on this site? I have seen your postings before and you are NOT nice.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#4: 4 Weeks Ago

re: Can someone help me with Nim?


Quote:

Originally Posted by massconfusion149 View Post

Why are you such a jerk on this site?

Haha :)

I take the time to research people's questions in order to try and help them. I expect the same amount of effort from people asking questions.

If you don't show any effort in trying to solve your question it feels like you are insulting me. I mean who wouldn't be insulted ? It feels like you expect me to put in more effort than you are in trying to solve your problem. Instead of being a jerk and stating this I use a template-post that the moderators have come up with to answer this type of lack of effort. Everyone is treated this way if they don't first at least attempt their problem (and show us their attempt).

If you show me any sort of attempt at your problem I will go out of my way to help you understand where you're going wrong.

So, now I hope you understand my response.

Cheers,

-Frinny

(PS maybe you didn't use the right words when googling. Your question is "how do I use Java to generate a random number" so I googled "generate random number java" and found a link containing the above posted Java code that illustrates how to generate random numbers.)
Reply

Tags
java, nim, random integer