本文整理汇总了C#中ArrayList.Shuffle方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayList.Shuffle方法的具体用法?C# ArrayList.Shuffle怎么用?C# ArrayList.Shuffle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayList
的用法示例。
在下文中一共展示了ArrayList.Shuffle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RandomIndexing
public void RandomIndexing()
{
Random ran = new Random(6754);
int length = 1000;
int[] a = new int[length];
int[] b = new int[length];
ArrayList<int> shuffle = new ArrayList<int>(length);
IPriorityQueueHandle<int>[] h = new IPriorityQueueHandle<int>[length];
for (int i = 0; i < length; i++)
{
shuffle.Add(i);
queue.Add(ref h[i], a[i] = ran.Next());
b[i] = ran.Next();
Assert.IsTrue(queue.Check());
}
Assert.IsTrue(queue.Check());
shuffle.Shuffle(ran);
for (int i = 0; i < length; i++)
{
int j = shuffle[i];
Assert.AreEqual(a[j], queue[h[j]]);
queue[h[j]] = b[j];
Assert.AreEqual(b[j], queue[h[j]]);
Assert.IsTrue(queue.Check());
}
}
示例2: RandomWithDeleteHandles
public void RandomWithDeleteHandles()
{
Random ran = new Random(6754);
int length = 1000;
int[] a = new int[length];
ArrayList<int> shuffle = new ArrayList<int>(length);
IPriorityQueueHandle<int>[] h = new IPriorityQueueHandle<int>[length];
for (int i = 0; i < length; i++)
{
shuffle.Add(i);
queue.Add(ref h[i], a[i] = ran.Next());
Assert.IsTrue(queue.Check());
}
Assert.IsTrue(queue.Check());
shuffle.Shuffle(ran);
for (int i = 0; i < length; i++)
{
int j = shuffle[i];
Assert.AreEqual(a[j], queue.Delete(h[j]));
Assert.IsTrue(queue.Check());
}
Assert.IsTrue(queue.IsEmpty);
}
示例3: Main
static void Main(string[] args)
{
// load documents
Utils.VerboseLine("Loading documents ...");
string[] docs = File.ReadAllLines("C:\\newwork\\testclustering\\data\\yahoofinance.txt");
BowSpace bowSpace = new BowSpace();
bowSpace.StopWords = StopWords.EnglishStopWords;
bowSpace.Stemmer = new PorterStemmer();
bowSpace.WordWeightType = WordWeightType.TfIdf;
RegexTokenizer tokenizer = new RegexTokenizer();
tokenizer.IgnoreUnknownTokens = true;
bowSpace.Tokenizer = tokenizer;
bowSpace.Initialize(docs);
// compute layout
SemanticSpaceLayout semSpc = new SemanticSpaceLayout(bowSpace);
Vector2D[] coords = semSpc.ComputeLayout();
// build spatial index
//Utils.VerboseLine("Building spatial index ...");
//SpatialIndex2D spatIdx = new SpatialIndex2D();
//spatIdx.BuildIndex(coords);
//spatIdx.InsertPoint(9000, new Vector2D(1000, 1000));
//ArrayList<IdxDat<Vector2D>> points = spatIdx.GetPoints(new Vector2D(0.5, 0.5), 0.1);
//Utils.VerboseLine("Number of retrieved points: {0}.", points.Count);
ArrayList<Vector2D> tmp = new ArrayList<Vector2D>(coords);
tmp.Shuffle();
//tmp.RemoveRange(1000, tmp.Count - 1000);
// compute elevation
StreamWriter writer = new StreamWriter("c:\\elev.txt");
LayoutSettings ls = new LayoutSettings(800, 600);
ls.AdjustmentType = LayoutAdjustmentType.Soft;
ls.StdDevMult = 2;
ls.FitToBounds = true;
ls.MarginVert = 50;
ls.MarginHoriz = 50;
double[,] zMtx = VisualizationUtils.ComputeLayoutElevation(tmp, ls, 150, 200);
VisualizationUtils.__DrawElevation__(tmp, ls, 300, 400).Save("c:\\elev.bmp");
for (int row = 0; row < zMtx.GetLength(0); row++)
{
for (int col = 0; col < zMtx.GetLength(1); col++)
{
writer.Write("{0}\t", zMtx[row, col]);
}
writer.WriteLine();
}
writer.Close();
// output coordinates
StreamWriter tsvWriter = new StreamWriter("c:\\layout.tsv");
for (int i = 0; i < coords.Length; i++)
{
//if (i < points.Count)
//{
// tsvWriter.WriteLine("{0}\t{1}\t{2}\t{3}", coords[i].X, coords[i].Y, points[i].Dat.X, points[i].Dat.Y);
//}
//else
{
tsvWriter.WriteLine("{0}\t{1}", coords[i].X, coords[i].Y);
}
}
tsvWriter.Close();
//// get document names
//int k = 0;
//ArrayList<Pair<string, Vector2D>> layout = new ArrayList<Pair<string, Vector2D>>();
//foreach (string doc in docs)
//{
// string[] docInfo = doc.Split(' ');
// layout.Add(new Pair<string, Vector2D>(docInfo[0], coords[k++]));
//}
//Console.WriteLine(coords.Length);
//Console.WriteLine(layout.Count);
//StreamWriter writer = new StreamWriter("c:\\vidCoords.txt");
//foreach (Pair<string, Vector2D> docPos in layout)
//{
// writer.WriteLine("{0}\t{1}\t{2}", docPos.First, docPos.Second.X, docPos.Second.Y);
//}
//writer.Close();
}