C# 乱数生成
新しいC#の書き方に直して行くべく
重複のない乱数列を生成するものを書いてみた
C#らしくない場所のツッコミお願いします
※本題と関係ないことに対するツッコミは無視します
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace sort_cs
{
class Program
{
static void Main(string[] args)
{
var rnd = new NumberArray(10).ToList();
}
}class NumberArray
{
private int[] number_;public NumberArray(int count)
{
number_ = new int[count];var rnd = new int[count];
for (int i = 0; i < count; i++)
{
rnd[i] = i;
}for (int i = 0, size = count; i < count; i++, size--)
{
var pos = new Random().Next(size);
number_[i] = rnd[pos];for (int j = pos; j < size - 1; j++)
{
rnd[j] = rnd[j + 1];
}
}
}public int[] ToList()
{
return number_;
}
}
}
生成される rnd 配列は以下の通り(例です)
3 2 5 7 1 8 9 0 4 6
次はこの乱数列をソートする方法