Skip to main content
Code Review

Return to Question

replaced http://tex.stackexchange.com/ with https://tex.stackexchange.com/
Source Link

I want to randomly permute a finite list in the most effective and efficient way in C#. My attempt is as follows.

/*===================================*
 * Compile it to produce Shuffle.exe *
 * ==================================*/
using System;
using System.Collections.Generic;
using System.IO;
namespace Shuffle
{
 class Program
 {
 static void Main(string[] args)
 {
 int Columns = int.Parse(args[0]);
 int Rows = int.Parse(args[1]);
 int Seed = int.Parse(args[2]);
 string OutputFilename = args[3];
 List<string> OrderedList = new List<string>();
 for (int x = 0; x < Columns; x++)
 for (int y = 0; y < Rows; y++)
 OrderedList.Add(string.Format("{{{0},{1}}}", x, y));
 Random rnd = new Random(Seed);
 List<string> ShuffledList = new List<string>();
 for (int i = 0; i < Columns * Rows; i++)
 {
 int x = rnd.Next(OrderedList.Count);
 ShuffledList.Add(OrderedList[x]);
 OrderedList.RemoveAt(x);
 }
 using (StreamWriter sw = new StreamWriter(OutputFilename))
 {
 foreach (string s in ShuffledList)
 sw.WriteLine(s);
 }
 }
 }
}

This program will be used in my production my production. Could you review whether or not my code is already the most efficient and effective in C#?

I want to randomly permute a finite list in the most effective and efficient way in C#. My attempt is as follows.

/*===================================*
 * Compile it to produce Shuffle.exe *
 * ==================================*/
using System;
using System.Collections.Generic;
using System.IO;
namespace Shuffle
{
 class Program
 {
 static void Main(string[] args)
 {
 int Columns = int.Parse(args[0]);
 int Rows = int.Parse(args[1]);
 int Seed = int.Parse(args[2]);
 string OutputFilename = args[3];
 List<string> OrderedList = new List<string>();
 for (int x = 0; x < Columns; x++)
 for (int y = 0; y < Rows; y++)
 OrderedList.Add(string.Format("{{{0},{1}}}", x, y));
 Random rnd = new Random(Seed);
 List<string> ShuffledList = new List<string>();
 for (int i = 0; i < Columns * Rows; i++)
 {
 int x = rnd.Next(OrderedList.Count);
 ShuffledList.Add(OrderedList[x]);
 OrderedList.RemoveAt(x);
 }
 using (StreamWriter sw = new StreamWriter(OutputFilename))
 {
 foreach (string s in ShuffledList)
 sw.WriteLine(s);
 }
 }
 }
}

This program will be used in my production. Could you review whether or not my code is already the most efficient and effective in C#?

I want to randomly permute a finite list in the most effective and efficient way in C#. My attempt is as follows.

/*===================================*
 * Compile it to produce Shuffle.exe *
 * ==================================*/
using System;
using System.Collections.Generic;
using System.IO;
namespace Shuffle
{
 class Program
 {
 static void Main(string[] args)
 {
 int Columns = int.Parse(args[0]);
 int Rows = int.Parse(args[1]);
 int Seed = int.Parse(args[2]);
 string OutputFilename = args[3];
 List<string> OrderedList = new List<string>();
 for (int x = 0; x < Columns; x++)
 for (int y = 0; y < Rows; y++)
 OrderedList.Add(string.Format("{{{0},{1}}}", x, y));
 Random rnd = new Random(Seed);
 List<string> ShuffledList = new List<string>();
 for (int i = 0; i < Columns * Rows; i++)
 {
 int x = rnd.Next(OrderedList.Count);
 ShuffledList.Add(OrderedList[x]);
 OrderedList.RemoveAt(x);
 }
 using (StreamWriter sw = new StreamWriter(OutputFilename))
 {
 foreach (string s in ShuffledList)
 sw.WriteLine(s);
 }
 }
 }
}

This program will be used in my production. Could you review whether or not my code is already the most efficient and effective in C#?

improved title
Source Link
Adam
  • 5.2k
  • 1
  • 30
  • 47

Could you review whether or not my code is already the most efficient and effective Randomly Permute Elements in C#?a List

I want to randomly permutatepermute a finite list in the most effective and efficient way in C#. My attempt is as follows.

/*===================================*
 * Compile it to produce Shuffle.exe *
 * ==================================*/
using System;
using System.Collections.Generic;
using System.IO;
namespace Shuffle
{
 class Program
 {
 static void Main(string[] args)
 {
 int Columns = int.Parse(args[0]);
 int Rows = int.Parse(args[1]);
 int Seed = int.Parse(args[2]);
 string OutputFilename = args[3];
 List<string> OrderedList = new List<string>();
 for (int x = 0; x < Columns; x++)
 for (int y = 0; y < Rows; y++)
 OrderedList.Add(string.Format("{{{0},{1}}}", x, y));
 Random rnd = new Random(Seed);
 List<string> ShuffledList = new List<string>();
 for (int i = 0; i < Columns * Rows; i++)
 {
 int x = rnd.Next(OrderedList.Count);
 ShuffledList.Add(OrderedList[x]);
 OrderedList.RemoveAt(x);
 }
 using (StreamWriter sw = new StreamWriter(OutputFilename))
 {
 foreach (string s in ShuffledList)
 sw.WriteLine(s);
 }
 }
 }
}

This program will be used in my production. Could you review whether or not my code is already the most efficient and effective in C#?

Could you review whether or not my code is already the most efficient and effective in C#?

I want to randomly permutate a finite list in the most effective and efficient way in C#. My attempt is as follows.

/*===================================*
 * Compile it to produce Shuffle.exe *
 * ==================================*/
using System;
using System.Collections.Generic;
using System.IO;
namespace Shuffle
{
 class Program
 {
 static void Main(string[] args)
 {
 int Columns = int.Parse(args[0]);
 int Rows = int.Parse(args[1]);
 int Seed = int.Parse(args[2]);
 string OutputFilename = args[3];
 List<string> OrderedList = new List<string>();
 for (int x = 0; x < Columns; x++)
 for (int y = 0; y < Rows; y++)
 OrderedList.Add(string.Format("{{{0},{1}}}", x, y));
 Random rnd = new Random(Seed);
 List<string> ShuffledList = new List<string>();
 for (int i = 0; i < Columns * Rows; i++)
 {
 int x = rnd.Next(OrderedList.Count);
 ShuffledList.Add(OrderedList[x]);
 OrderedList.RemoveAt(x);
 }
 using (StreamWriter sw = new StreamWriter(OutputFilename))
 {
 foreach (string s in ShuffledList)
 sw.WriteLine(s);
 }
 }
 }
}

This program will be used in my production. Could you review whether or not my code is already the most efficient and effective in C#?

Randomly Permute Elements in a List

I want to randomly permute a finite list in the most effective and efficient way in C#. My attempt is as follows.

/*===================================*
 * Compile it to produce Shuffle.exe *
 * ==================================*/
using System;
using System.Collections.Generic;
using System.IO;
namespace Shuffle
{
 class Program
 {
 static void Main(string[] args)
 {
 int Columns = int.Parse(args[0]);
 int Rows = int.Parse(args[1]);
 int Seed = int.Parse(args[2]);
 string OutputFilename = args[3];
 List<string> OrderedList = new List<string>();
 for (int x = 0; x < Columns; x++)
 for (int y = 0; y < Rows; y++)
 OrderedList.Add(string.Format("{{{0},{1}}}", x, y));
 Random rnd = new Random(Seed);
 List<string> ShuffledList = new List<string>();
 for (int i = 0; i < Columns * Rows; i++)
 {
 int x = rnd.Next(OrderedList.Count);
 ShuffledList.Add(OrderedList[x]);
 OrderedList.RemoveAt(x);
 }
 using (StreamWriter sw = new StreamWriter(OutputFilename))
 {
 foreach (string s in ShuffledList)
 sw.WriteLine(s);
 }
 }
 }
}

This program will be used in my production. Could you review whether or not my code is already the most efficient and effective in C#?

Tweeted twitter.com/#!/StackCodeReview/status/244858105941344256
Source Link
kiss my armpit
  • 335
  • 1
  • 4
  • 11

Could you review whether or not my code is already the most efficient and effective in C#?

I want to randomly permutate a finite list in the most effective and efficient way in C#. My attempt is as follows.

/*===================================*
 * Compile it to produce Shuffle.exe *
 * ==================================*/
using System;
using System.Collections.Generic;
using System.IO;
namespace Shuffle
{
 class Program
 {
 static void Main(string[] args)
 {
 int Columns = int.Parse(args[0]);
 int Rows = int.Parse(args[1]);
 int Seed = int.Parse(args[2]);
 string OutputFilename = args[3];
 List<string> OrderedList = new List<string>();
 for (int x = 0; x < Columns; x++)
 for (int y = 0; y < Rows; y++)
 OrderedList.Add(string.Format("{{{0},{1}}}", x, y));
 Random rnd = new Random(Seed);
 List<string> ShuffledList = new List<string>();
 for (int i = 0; i < Columns * Rows; i++)
 {
 int x = rnd.Next(OrderedList.Count);
 ShuffledList.Add(OrderedList[x]);
 OrderedList.RemoveAt(x);
 }
 using (StreamWriter sw = new StreamWriter(OutputFilename))
 {
 foreach (string s in ShuffledList)
 sw.WriteLine(s);
 }
 }
 }
}

This program will be used in my production. Could you review whether or not my code is already the most efficient and effective in C#?

lang-cs

AltStyle によって変換されたページ (->オリジナル) /