using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
{
class RandomNumber
{
static void Main(string[] args)
{
int randomNumberGenerator;
Random randomGenerator = new Random();
randomNumberGenerator = randomGenerator.Next(Convert.ToInt32(args[0]), Convert.ToInt32(args[1]));
for (int number = 0; number <= 4; number++)
Console.Write("{0} ",randomNumberGenerator);
}
}
}
Random Number Help
Started by Alex_j, Nov 13 2009 04:31 AM
3 replies to this topic
#1
Posted 13 November 2009 - 04:31 AM
Hi, Im new to C# and I have to generate 10 random numbers between two values passed through arguments at the command line, the numbers however are the same :confused: What am I doing wrong?
|
|
|
#2
Posted 13 November 2009 - 07:55 AM
You are only calling for your random number one time. You need to put it into the loop so it will call each time.
static void Main(string[] args)
{
int randomNumberGenerator;
Random randomGenerator = new Random();
for (int number = 0; number <= 4; number++)
{
randomNumberGenerator = randomGenerator.Next(1, 100);
Console.WriteLine("{0}", randomNumberGenerator);
}
Console.Read();
}
#3
Posted 13 November 2009 - 07:57 AM
Shouldn't int number be 10, if you want it to loop 10 times?
#4
Posted 13 November 2009 - 08:01 AM
He is looping 5 time all he needs to do is change the 4 to a 9 for 10 loops.


Sign In
Create Account


Back to top









