Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-01-2010
Member
 
Join Date: Dec 2009
Posts: 48
C sharp program to print random numbers

Hi All,

I am new in the field of C sharp programming. That why I am getting too much difficulties while coding simple C sharp programs. I have to write the C sharp program to print the Random number. I have tried one code logic, but I am getting too much errors during it's code execution. Is anyone has the C sharp code to print the random number then please share with me. I would greatly appreciate your help over this C sharp program.
Reply With Quote
  #2  
Old 12-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: C sharp program to print random numbers

Hi,

Please refer the following C sharp program which prints the random number:
Quote:
using System;

class CSHRPProgram

{
static void Main(string args[])

{
Random RandmNum = new Random();

int k = RandmNum.Next();

Console.WriteLine(k);

Console.Read();
}
}
Reply With Quote
  #3  
Old 12-01-2010
Member
 
Join Date: May 2008
Posts: 2,008
Re: C sharp program to print random numbers

Hi friend,

You need to use the below mentioned method in your C sharp program for random number. Here I used the 'RandNumber()' method to print eh random number. Then I defined the 'rm' variable as a random variable to calculate random number.
Quote:
private int RandNumber(int m, int n, )
{
Random rm = new Random();

return rm.Next(m, m);

}
Reply With Quote
  #4  
Old 12-01-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: C sharp program to print random numbers

Have you tried following C sharp code for random number?
Quote:
bool [] nmbers = new bool[10];

Random rd = new Random();
int hs = 0;
while(hs < 5)
{
int ps = rd.Next(9);
if (nmbers[pos] == true)

continue;

nmbers[pos] = true;

hs++;
}

Console.WriteLine("Random Numbers : ");

for(int a=0; a<10; a++)
{

if (nmbers[a] == true)

Console.Write("{0} ", a.ToString());

}
Console.WriteLine();
Reply With Quote
  #5  
Old 12-01-2010
Member
 
Join Date: May 2008
Posts: 2,293
Re: C sharp program to print random numbers

C sharp program for random numbers:
Quote:
using System;

using System.Collections.Generic;

using System.Text;

namespace CSRAD

{
class Pm

{
static void Main(string[] args)

{
int k = 0;
int l= 0;
}
}


class CSDEMO
{

private static int n;

public static int N { get { return n; } }

static CSDEMO()
{
Random rf = new Random();
n = rf.Next();
}
}
}
Reply With Quote
  #6  
Old 12-01-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: C sharp program to print random numbers

Try something below in you random number program of C sharp:
Quote:
Random r = new Random();

bool z = new bool [10];
int c = 0;

while(c < 10)
{

int pos = r.Next(9);

if (z[pos] == true)

continue;

z[pos] = true;

c++;

}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "C sharp program to print random numbers"
Thread Thread Starter Forum Replies Last Post
Program to print GCD of given numbers Bhavesh_seth Software Development 5 15-03-2011 08:03 PM
C Program to print Combination of numbers Prashobh Mallu Software Development 6 26-03-2010 09:21 PM
Need C program code to count numbers of negative & positive numbers Sarfaraj Khan Software Development 5 16-01-2010 02:00 PM
Random Numbers in C Rob Dizzle Software Development 5 30-12-2009 10:37 AM
Program to print odd and even numbers roodiii Software Development 3 30-11-2009 02:13 PM


All times are GMT +5.5. The time now is 06:25 PM.