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


C# IRandomGenerator.GetRandomNumber方法代码示例

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


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

示例1: GenerateData

        public void GenerateData(CompanyEntities data, IRandomGenerator random, int count)
        {
            var employeeIds = data.Employees.Select(x => x.EmployeeId);
            var projectIds = data.Projects.Select(x => x.ProjectId).ToList();

            foreach (var employee in employeeIds)
            {
                var employeeProjects = random.GetRandomNumber((int)count / 2, (int)(count * 1.5));

                for (var i = 0; i < employeeProjects; i++)
                {
                    var projectId = projectIds[random.GetRandomNumber(1, projectIds.Count - 1)];

                    var startDate = DateTime.Now.AddDays(-random.GetRandomNumber(-500, 1000));
                    var endDate = startDate.AddDays(random.GetRandomNumber(1, 1234));

                    var employeeInProj = new Employees_Projects
                    {
                        ProjectId = projectId,
                        Startdate = startDate,
                        Enddate = endDate,
                        EmployeeId = employee
                    };

                    data.Employees_Projects.Add(employeeInProj);
                }
            }
        }
开发者ID:cwetanow,项目名称:Telerik,代码行数:28,代码来源:EmployeesInProjectsDataGenerator.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)
        {
            var employeeIds = data.Employees.Select(e => e.Id).ToList();
            var projectIds = data.Projects.Select(p => p.Id).ToList();

            foreach (var employeeId in employeeIds)
            {
                var employeeProjectsCount = random.GetRandomNumber((int)(count * 0.5), (int)(count * 1.5));
                var currentProjects = new HashSet<int>();

                while (currentProjects.Count < employeeProjectsCount)
                {
                    var randomProjectId = projectIds[random.GetRandomNumber(0, projectIds.Count - 1)];
                    currentProjects.Add(randomProjectId);
                }

                foreach (var projectId in currentProjects)
                {
                    var endDateTimeSpan = random.GetRandomNumber(-500, 1000);
                    var startDateTimeSpan = endDateTimeSpan + random.GetRandomNumber(1, 500);

                    data.EmployeesInProjects.Add(new EmployeesInProject
                                                     {
                                                         EmployeeId = employeeId,
                                                         ProjectId = projectId,
                                                         StartDate = DateTime.Now.AddDays(-startDateTimeSpan),
                                                         EndDate = DateTime.Now.AddDays(-endDateTimeSpan)
                                                     });
                }
            }
        }
开发者ID:ilkodzhambazov,项目名称:Databases,代码行数:31,代码来源:EmployeesInProjectsDataGenerator.cs

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: GenerateData

        public void GenerateData(CompanyEntities data, IRandomGenerator random, int count)
        {
            var employeeIds = data.Employees.Select(e => e.Id).ToList();

            foreach (var employeeId in employeeIds)
            {
                var reportsCount = random.GetRandomNumber((int)(0.5 * count), (int)(1.5 * count));

                for (int i = 0; i < reportsCount; i++)
                {
                    var timeSpanForReport = random.GetRandomNumber(0, 60 * 60 * 24 * 1000);

                    var report = new Report
                                     {
                                         EmployeeId = employeeId,
                                         Time = DateTime.Now.AddSeconds(-timeSpanForReport)
                                     };

                    data.Reports.Add(report);
                }
            }
        }
开发者ID:ilkodzhambazov,项目名称:Databases,代码行数:22,代码来源:ReportsDataGenerator.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: 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


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