1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace appbigdata 9 {10 class ParticlesGenerator11 {12 13 public void GenerateParticles(int count)14 {15 String fileName = @"C:\opengl\data\random.xyz";16 int seed = (int)(System.DateTime.Now.Ticks / 1000);17 Random random = new Random(seed);18 19 StreamWriter writer = new StreamWriter(fileName);20 try21 {22 writer.WriteLine(count);23 writer.WriteLine("Random Particles");24 String[] particleTypes = new String[] { "C", "H" };25 int maxValue = count;26 for (int i = 0; i < count; i++)27 {28 double x = random.Next(maxValue) * 0.01;29 double y = random.Next(maxValue) * 0.01;30 double z = random.Next(maxValue) * 0.001;31 double v = random.NextDouble();32 int index = v >= 0.5d ? 0 : 1;33 writer.WriteLine(String.Format("{0} {1} {2} {3}", particleTypes[index], x, y, z));34 }35 }36 finally37 {38 writer.Close();39 }40 System.Console.WriteLine(String.Format("save to:{0}", fileName));41 42 43 }44 }45 }