当前位置: 首页>>代码示例>>C#>>正文


C# IRandomGenerator.GetRandomString方法代码示例

本文整理汇总了C#中IRandomGenerator.GetRandomString方法的典型用法代码示例。如果您正苦于以下问题:C# IRandomGenerator.GetRandomString方法的具体用法?C# IRandomGenerator.GetRandomString怎么用?C# IRandomGenerator.GetRandomString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRandomGenerator的用法示例。


在下文中一共展示了IRandomGenerator.GetRandomString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateData

        public void GenerateData(CompanyEntities data, IRandomGenerator random, int count)
        {
            var allAddedEmployees = new List<Employee>();
            var departmentIds = data.Departments.Select(d => d.Id).ToList();

            for (int i = 0; i < count; i++)
            {
                var employee = new Employee
                                   {
                                       FirstName = random.GetRandomString(random.GetRandomNumber(5, 20)),
                                       LastName = random.GetRandomString(random.GetRandomNumber(5, 20)),
                                       Salary = random.GetRandomNumber(50000, 200000),
                                       DepartmentId =
                                           departmentIds[random.GetRandomNumber(0, departmentIds.Count - 1)]
                                   };

                if (allAddedEmployees.Count > 0 && random.GetRandomNumber(1, 100) <= 95)
                {
                    employee.Employee1 = allAddedEmployees[random.GetRandomNumber(0, allAddedEmployees.Count - 1)];
                }

                allAddedEmployees.Add(employee);
            }

            data.Employees.AddRange(allAddedEmployees);
        }
开发者ID:nikistefanov,项目名称:Telerik-Academy-Homework,代码行数:26,代码来源:EmployeeDataGenerator.cs

示例2: GenerateData

        public void GenerateData(MongoDatabase db, IRandomGenerator random, int count)
        {
            string name;
            decimal price;
            int? upgradeToId;

            List<MongoUpgrade> mongoUpgrades = new List<MongoUpgrade>();

            for (int i = 0; i < count; i++)
            {
                name = random.GetRandomString(random.GetRandomNumber(5, 50));
                price = (decimal)(random.GetRandomNumber(10000, 1000000) / 100);
                upgradeToId = i;
                if(i % 4 == 0)
                {
                    upgradeToId = null;
                }

                var upgrade = new MongoUpgrade(name, price, upgradeToId);
                mongoUpgrades.Add(upgrade);
            }

            MongoCollection<MongoUpgrade> upgrades = db.GetCollection<MongoUpgrade>("Upgrades");
            upgrades.InsertBatch(mongoUpgrades);
        }
开发者ID:Astatine-Haphazard,项目名称:AstatineTeamwork,代码行数:25,代码来源:UpgradesDataGenerator.cs

示例3: GenerateData

 public void GenerateData(CompanyEntities data, IRandomGenerator random, int count)
 {
     for (int i = 0; i < count; i++)
     {
         var project = new Project { Name = random.GetRandomString(random.GetRandomNumber(5, 50)) };
         data.Projects.Add(project);
     }
 }
开发者ID:ilkodzhambazov,项目名称:Databases,代码行数:8,代码来源:ProjectsDataGenerator.cs

示例4: GenerateAlbums

        public List<Album> GenerateAlbums(IRandomGenerator generator, int count)
        {
            var albums = new List<Album>();

            for (var i = 0; i < count; i++)
            {
                var album = new Album()
                {
                    Title = generator.GetRandomString(generator.GetRandomNumber(5, 20)),
                    Year = generator.GetRandomNumber(DateTime.Now.AddYears(-50).Year, DateTime.Now.Year),
                    Producer = generator.GetRandomString(generator.GetRandomNumber(5, 20)),
                    Artists = new List<Artist>(),
                    Songs = new List<Song>()
                };
                albums.Add(album);
            }

            return albums;
        }
开发者ID:Nikolay-D,项目名称:WebServicesAndCloudTechnologies,代码行数:19,代码来源:DataGenerator.cs

示例5: GenerateData

        public void GenerateData(MongoDatabase db, IRandomGenerator random, int count)
        {
            int? customId = 0;
            string name;
            string position;

            List<MongoPilot> mongoPilots = new List<MongoPilot>();

            for (int i = 1; i <= count; i++)
            {
                customId = i % 4 == 0 ? 0 : i;
                name = random.GetRandomString(random.GetRandomNumber(5, 50));
                position = random.GetRandomString(random.GetRandomNumber(5, 50));
                var pilot = new MongoPilot(customId, name, position);
                mongoPilots.Add(pilot);
            }

            MongoCollection<MongoPilot> pilots = db.GetCollection<MongoPilot>("Pilots");
            pilots.InsertBatch(mongoPilots);
        }
开发者ID:Astatine-Haphazard,项目名称:AstatineTeamwork,代码行数:20,代码来源:PilotDataGenerator.cs

示例6: GenerateData

        public void GenerateData(CompanyEntities data, IRandomGenerator random, int count)
        {
            for (var i = 0; i < count; i++)
            {
                var department = new Department
                {
                    Name = random.GetRandomString(random.GetRandomNumber(10, 50))
                };

                data.Departments.Add(department);
            }
        }
开发者ID:cwetanow,项目名称:Telerik,代码行数:12,代码来源:DepartmentDataGenerator.cs

示例7: GenerateArtists

        public List<Artist> GenerateArtists(IRandomGenerator generator, int count)
        {
            var artists = new List<Artist>();

            for (var i = 0; i < count; i++)
            {
                var artist = new Artist()
                {
                    Name = generator.GetRandomString(generator.GetRandomNumber(5, 20)),
                    DateOfBirth = generator.GetRandomDateTime(DateTime.Now.AddYears(-90), DateTime.Now.AddYears(-20)).ToString(),
                    Country = generator.GetRandomString(generator.GetRandomNumber(5, 20)),
                    Albums = new List<Album>()
                    {
                        new Album()
                        {
                            Title = generator.GetRandomString(generator.GetRandomNumber(5, 20)),
                            Year = generator.GetRandomNumber(DateTime.Now.AddYears(-50).Year, DateTime.Now.Year),
                            Producer = generator.GetRandomString(generator.GetRandomNumber(5, 20)),
                            Artists = new List<Artist>(),
                            Songs = new List<Song>()
                        }
                    },
                    Songs = new List<Song>()
                    {
                        new Song()
                        {
                            Title = generator.GetRandomString(generator.GetRandomNumber(5, 20)),
                            Genre = generator.GetRandomString(generator.GetRandomNumber(5, 20)),
                            Year = generator.GetRandomNumber(DateTime.Now.AddYears(-50).Year, DateTime.Now.Year),
                            ArtistId = null,
                            AlbumId = null
                        }
                    }
                };

                artists.Add(artist);
            }
            return artists;
        }
开发者ID:Nikolay-D,项目名称:WebServicesAndCloudTechnologies,代码行数:39,代码来源:DataGenerator.cs

示例8: GenerateData

        public void GenerateData(CompanyEntities data, IRandomGenerator random, int count)
        {
            var uniqueNames = new HashSet<string>();

            while (uniqueNames.Count < count)
            {
                uniqueNames.Add(random.GetRandomString(random.GetRandomNumber(10, 50)));
            }

            foreach (var uniqueName in uniqueNames)
            {
                var department = new Department { Name = uniqueName };
                data.Departments.Add(department);
            }
        }
开发者ID:ilkodzhambazov,项目名称:Databases,代码行数:15,代码来源:DepartmentDataGenerator.cs

示例9: GenerateData

        public void GenerateData(CompanyEntities data, IRandomGenerator random, int count)
        {
            var allEmployees = new List<Employee>();

            for (var i = 0; i < count; i++)
            {
                var employee = new Employee
                {
                    DepartmentId = random.GetRandomNumber(1, data.Departments.Count()),
                    Firstname = random.GetRandomString(random.GetRandomNumber(5, 20)),
                    Lastname = random.GetRandomString(random.GetRandomNumber(5, 20)),
                    Salary = random.GetRandomNumber(50000, 200000)
                };

                if (allEmployees.Any() && random.GetRandomNumber(1, 100) <= 95)
                {
                    employee.Employee1 = allEmployees[random.GetRandomNumber(0, data.Employees.Count() - 1)];
                }

                allEmployees.Add(employee);
            }

            data.Employees.AddRange(allEmployees);
        }
开发者ID:cwetanow,项目名称:Telerik,代码行数:24,代码来源:EmployeeDataGenerator.cs

示例10: GenerateData

        public void GenerateData(ComputersEntities data, IRandomGenerator random, int count)
        {
            var vendorIds = data.Vendors
                  .Select(x => x.VendorId)
                  .ToList();

            var cpuIds = data.Cpus
                .Select(x => x.CpuId)
                .ToList();

            var allGpus = data.Gpus
                .ToList();

            var allStorageDevices = data.StorageDevices
                .ToList();

            for (var i = 0; i < count; i++)
            {
                var computer = new Computer()
                {
                    VendorId = vendorIds[random.GetRandomNumber(0, vendorIds.Count - 1)],
                    Model = random.GetRandomString(random.GetRandomNumber(1, 30)),
                    CpuId = cpuIds[random.GetRandomNumber(1, cpuIds.Count - 1)],
                    MemoryInGb = random.GetRandomNumber(1, 64),
                    Type = i < count / 3 ? "ultrabook" : i > (count / 3) * 2 ? "notebook" : "desktop",
                };

                var gpuCount = random.GetRandomNumber(1, 5);

                for (var j = 0; j < gpuCount; j++)
                {
                    computer.Gpus.Add(allGpus[random.GetRandomNumber(0, allGpus.Count - 1)]);
                }
                var storageDevicesCount = random.GetRandomNumber(1, 5);

                for (var j = 0; j < storageDevicesCount; j++)
                {
                    computer.StorageDevices.Add(allStorageDevices[random.GetRandomNumber(0, allStorageDevices.Count - 1)]);
                }

                data.Computers.Add(computer);
            }
        }
开发者ID:cwetanow,项目名称:Telerik,代码行数:43,代码来源:ComputerDataGenerator.cs

示例11: GenerateData

        public void GenerateData(ComputersEntities data, IRandomGenerator random, int count)
        {
            var vendorIds = data.Vendors
                .Select(x => x.VendorId)
                .ToList();

            for (var i = 0; i < count; i++)
            {
                var gpu = new Gpu
                {
                    MemoryInGb = random.GetRandomNumber(1, 32),
                    VendorId = vendorIds[random.GetRandomNumber(0, vendorIds.Count - 1)],
                    Model = random.GetRandomString(random.GetRandomNumber(1, 30)),
                    Type = i % 3 == 0 ? "internal" : "external"
                };

                data.Gpus.Add(gpu);
            }
        }
开发者ID:cwetanow,项目名称:Telerik,代码行数:19,代码来源:GpuDataGenerator.cs

示例12: Generate

        public void Generate(int filesCount, IRandomGenerator random)
        {
            const int EntitiesPerFile = 3000;
            var manufacturers = random.GetRandomStrings(20, 7).ToList();
            var cities = random.GetRandomStrings(15, 8).ToList();
            var dealers = random.GetRandomStrings(20, 10).ToList();

            for (int i = 1; i <= filesCount; i++)
            {
                var data = new List<Car>();
                for (int j = 0; j < EntitiesPerFile; j++)
                {
                    var car = new Car
                                  {
                                      ManufacturerName = random.GetRandomElement(manufacturers),
                                      Model = random.GetRandomString(20),
                                      Price = random.GetRandomNumber(1000, 200000),
                                      TransmissionType =
                                          (random.GetRandomNumber(1, 3) == 1)
                                              ? TransmissionType.Automatic
                                              : TransmissionType.Manual,
                                      Year = (ushort)random.GetRandomNumber(1990, 2015),
                                      Dealer =
                                          new Dealer
                                              {
                                                  City = random.GetRandomElement(cities),
                                                  Name = random.GetRandomElement(dealers)
                                              }
                                  };

                    data.Add(car);
                }

                using (var writer = new StreamWriter(string.Format("data.{0}.json", i)))
                {
                    writer.Write(JsonConvert.SerializeObject(data));
                }
            }
        }
开发者ID:ilkodzhambazov,项目名称:Databases,代码行数:39,代码来源:JsonFilesGenerator.cs

示例13: GenerateShipTypeData

        public List<MongoShipType> GenerateShipTypeData(MongoDatabase db, IRandomGenerator random, int count)
        {
            string type;
            DateTime modelAge;
            decimal price;

            DateTime after = new DateTime(1970, 1, 1, 23, 59, 59);
            DateTime before = new DateTime(2015, 12, 30, 23, 59, 59);

            List<MongoShipType> mongoShipTypes = new List<MongoShipType>();

            for (int i = 0; i < count; i++)
            {
                type = random.GetRandomString(random.GetRandomNumber(5, 50));
                modelAge = random.GetRandomDate(after, before);
                price = (decimal)(random.GetRandomNumber(10000, 1000000) / 100);

                var shipType = new MongoShipType(type, modelAge, price);
                mongoShipTypes.Add(shipType);
            }

            return mongoShipTypes;
        }
开发者ID:Astatine-Haphazard,项目名称:AstatineTeamwork,代码行数:23,代码来源:ShipDataGenerator.cs

示例14: GenerateData

        public void GenerateData(MongoDatabase db, IRandomGenerator random, int count)
        {
            int customId = 0;
            string name;
            MongoShipType type;

            List<MongoShipType> shipTypes = GenerateShipTypeData(db, random, 10);
            int index;

            List<MongoShip> mongoShips = new List<MongoShip>();

            for (int i = 1; i <= count; i++)
            {
                customId = i;
                name = random.GetRandomString(random.GetRandomNumber(5, 50));
                index = random.GetRandomNumber(1, 9);
                type = shipTypes[index];
                var ship = new MongoShip(customId, name, type);
                mongoShips.Add(ship);
            }

            MongoCollection<MongoShip> ships = db.GetCollection<MongoShip>("Ships");
            ships.InsertBatch(mongoShips);
        }
开发者ID:Astatine-Haphazard,项目名称:AstatineTeamwork,代码行数:24,代码来源:ShipDataGenerator.cs

示例15: GenerateSongs

        public List<Song> GenerateSongs(IRandomGenerator generator, int count)
        {
            var songs = new List<Song>();

            for (var i = 0; i < count; i++)
            {
                var song = new Song()
                {
                    Title = generator.GetRandomString(generator.GetRandomNumber(5, 20)),
                    Genre = generator.GetRandomString(generator.GetRandomNumber(5, 20)),
                    Year = generator.GetRandomNumber(DateTime.Now.AddYears(-50).Year, DateTime.Now.Year),
                    ArtistId = null,
                    AlbumId = null
                };
                songs.Add(song);
            }
            return songs;
        }
开发者ID:Nikolay-D,项目名称:WebServicesAndCloudTechnologies,代码行数:18,代码来源:DataGenerator.cs


注:本文中的IRandomGenerator.GetRandomString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。