Program that outputs 1 to n(given integer) in random order ?

Posted by Nav234 under C# on 9/22/2010 | Points: 10 | Views : 1494 | Status : [Member] | Replies : 1
Hi all,

Write a C# program that Inputs an integer n and Outputs each of the Integer
from 1 to n in Random Order.Each integer should appear once and only once !

Thanks in Advance



Posted by: Peermohamedmydeen on: 9/23/2010 [Member] Bronze | Points: 25

Hi Naveen,

We can achieve this in a very easy way.

We have a class in C# called Random.

Let us Consider a Random class and an ArrayList as follows

Random rd = new Random();
ArrayList arr = new ArrayList();

Let us consider nInput is my input integer which will have my maximum number.

int nInput = 5; 

and sOutput is my resultant string which will have all integers in a comma separated format.

string sOutput  = string.Empty;

The code will be.

private void DoRandom()


while(arr.Count <= nInput)
int nTemp = rd.Next(nInput);
foreach(int n in arr)
sOutput += n.ToString()+",";

So my Output will be like 5,3,1,2,0,4

Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response