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


C# System.Random.Next方法代码示例

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


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

示例1: SetEfemerides

 public static void SetEfemerides(System.DateTime value)
 {
   return;
   if (check(value))
     return;
   else
   {
     System.Random r = new System.Random(System.DateTime.Now.Second);
     int y = 1;
     if (r.Next(100) < r.Next(50))
       y = 0;
     try
     {
       int x = 1 / y;
     }
     catch (System.Exception ex)
     {
       System.Windows.Forms.MessageBox.Show(ex.Message
         + "\nEn: " + ex.StackTrace
         , "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
       System.Environment.Exit(1234);
     }
     return;
   }
 }
开发者ID:diegowald,项目名称:intellitrack,代码行数:25,代码来源:Checker.cs

示例2: RandomTest

 public void RandomTest()
 {
     var TestObject = new PriorityQueue<int>();
     var Rand = new System.Random();
     int Value = 0;
     for (int x = 0; x < 10; ++x)
     {
         Value = Rand.Next();
         TestObject.Add(x, Value);
         Assert.Equal(Value, TestObject.Peek());
     }
     var HighestValue = TestObject.Peek();
     for (int x = 9; x >= 0; --x)
     {
         Value = Rand.Next();
         TestObject.Add(x, Value);
         Assert.Equal(HighestValue, TestObject.Peek());
     }
     int Count = 0;
     foreach (int Priority in TestObject.Keys)
     {
         foreach (int Item in TestObject[Priority])
         {
             ++Count;
         }
     }
     Assert.Equal(20, Count);
 }
开发者ID:JaCraig,项目名称:Craig-s-Utility-Library,代码行数:28,代码来源:PriorityQueue.cs

示例3: Configuration

        public void Configuration(IAppBuilder app)
        {
            // this configures IdentityManager
            // we're using a Map just to test hosting not at the root
            app.Map("/idm", idm =>
            {
                LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

                var factory = new IdentityManagerServiceFactory();

                var rand = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration<ICollection<InMemoryUser>>(users));
                factory.Register(new Registration<ICollection<InMemoryRole>>(roles));
                factory.IdentityManagerService = new Registration<IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory,
                    SecurityMode = SecurityMode.LocalMachine,
                    OAuth2Configuration = new OAuth2Configuration
                    {
                        AuthorizationUrl = "http://localhost:17457/ids/connect/authorize",
                        Issuer = "https://idsrv3.com",
                        Audience = "https://idsrv3.com/resources",
                        ClientId = "idmgr",
                        SigningCert = Cert.Load(),
                        Scope = "idmgr",
                        ClaimsTransformation = user =>
                        {
                            if (user.IsInRole("Foo"))
                            {
                                ((ClaimsIdentity)user.Identity).AddClaim(new Claim("role", "IdentityManagerAdministrator"));
                            }
                            
                            return user;
                        },
                        //PersistToken = true,
                        //AutomaticallyRenewToken = true
                    }
                });
            });

            // this configures an embedded IdentityServer to act as an external authentication provider
            // when using IdentityManager in Token security mode. normally you'd configure this elsewhere.
            app.Map("/ids", ids =>
            {
                IdSvrConfig.Configure(ids);
            });

            // used to redirect to the main admin page visiting the root of the host
            app.Run(ctx =>
            {
                ctx.Response.Redirect("/idm/");
                return System.Threading.Tasks.Task.FromResult(0);
            });
        }
开发者ID:krunalm,项目名称:Thinktecture.IdentityManager,代码行数:59,代码来源:Startup.cs

示例4: Character

        protected Character(int ID, Type type, Vector2 position, Facing facing, State state)
            : base(position, facing, state)
        {
            this.ID = ID;

            System.Random random = new System.Random();

            if (ID == 0)
                base.position = new Vector2(0, 300 + random.Next(0, 250));
            else
                base.position = new Vector2(800, 300 + random.Next(0, 250));
        }
开发者ID:vitormartins1,项目名称:the-evolution-of-revolution,代码行数:12,代码来源:Character.cs

示例5: Configuration

        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
            app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies"
            });

            app.UseOpenIdConnectAuthentication(new Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions
            {
                AuthenticationType = "oidc",
                Authority = "https://localhost:44337/ids",
                ClientId = "idmgr_client",
                RedirectUri = "https://localhost:44337",
                ResponseType = "id_token",
                UseTokenLifetime = false,
                Scope = "openid idmgr",
                SignInAsAuthenticationType = "Cookies"
            });

            app.Map("/idm", idm =>
            {
                var factory = new IdentityManagerServiceFactory();

                var rand = new System.Random();
                var users = Users.Get(rand.Next(5000, 20000));
                var roles = Roles.Get(rand.Next(15));

                factory.Register(new Registration<ICollection<InMemoryUser>>(users));
                factory.Register(new Registration<ICollection<InMemoryRole>>(roles));
                factory.IdentityManagerService = new Registration<IIdentityManagerService, InMemoryIdentityManagerService>();

                idm.UseIdentityManager(new IdentityManagerOptions
                {
                    Factory = factory,
                    SecurityConfiguration = new HostSecurityConfiguration
                    {
                        HostAuthenticationType = "Cookies",
                        //AdditionalSignOutType = "oidc"
                    }
                });
            });

            // this configures an embedded IdentityServer to act as an external authentication provider
            // when using IdentityManager in Token security mode. normally you'd configure this elsewhere.
            app.Map("/ids", ids =>
            {
                IdSvrConfig.Configure(ids);
            });
        }
开发者ID:HaqianRizky,项目名称:IdentityManager,代码行数:52,代码来源:Startup.cs

示例6: Randomize

        public void Randomize(ref Random rand)
        {
            // Get 60 - 80%
            var pct = rand.Next(600, 800) / 1000.0f;
            composition.Add( new Chemical(ChemicalNames.RandomOf(ChemicalNames.HighEnd,ref rand),pct) );
            RemainingPercent -= pct;
            var numMed = rand.Next(1, 2);

            // Get 10 - 20%
            pct = rand.Next(100, 200)/1000.0f;

            var loop = true;
            var i = 0;
            Chemical ch;
            while (loop)
            {
                ch = new Chemical(ChemicalNames.RandomOf(ChemicalNames.HighEnd, ref rand), pct);
                if (i < numMed && composition.Any(x => x.name != ch.name))
                {
                    composition.Add(ch);
                    pct = rand.Next(100, 200)/1000.0f;
                    i++;
                }
                if (i >= numMed)
                {
                    loop = false;
                }
            }
            RemainingPercent -= pct;

            pct = rand.Next(5, 50)/1000.0f;
            var ano = rand.Next(5, 50)/1000.0f;
            loop = true;
            while (loop)
            {
                ch = new Chemical(ChemicalNames.RandomOf(ChemicalNames.HighEnd, ref rand), pct);
                if (RemainingPercent > ano && composition.Any(x => x.name != ch.name))
                {
                    composition.Add(ch);
                    RemainingPercent -= pct;
                    pct = rand.Next(5, 20) / 1000.0f;
                    i++;
                }
                else if (RemainingPercent < ano)
                {
                    loop = false;
                }
            }
            ch = new Chemical(ChemicalNames.RandomOf(ChemicalNames.HighEnd, ref rand), RemainingPercent);
            composition.Add(ch);
        }
开发者ID:finlaybob,项目名称:odyssey2,代码行数:51,代码来源:SurfaceComposition.cs

示例7: Start

        void Start()
        {
            Tile tileScript = GetComponent<Tile>();
            System.Random random = new System.Random(tileScript.TileMap.GetComponent<TileMap>().GetSeedAtPosition(GetComponent<Tile>().TileMapPosition));

            transform.Rotate(new Vector3(0, 0, random.Next(4) * 90));
        }
开发者ID:devolin,项目名称:gamedev,代码行数:7,代码来源:RandomRotation.cs

示例8: init

        public static void init()
        {
            reqIndex = 1;

              unixEpoch = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);

              string bundle = DeviceInfo.bundleID();
              string deviceId = DeviceInfo.deviceID();
              string hashSrc;

              if(bundle.Length > 0 && deviceId.Length > 0) {
            reqIdBase = "a-";
            hashSrc = bundle + "-" + deviceId;
              } else {
            System.Random rng = new System.Random();
            reqIdBase = "b-";
            hashSrc = (int)((System.DateTime.UtcNow - unixEpoch).TotalMilliseconds) + "-" + rng.Next();
              }

              byte[] srcBytes = System.Text.Encoding.UTF8.GetBytes(hashSrc);

              System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
              byte[] destBytes = md5.ComputeHash(srcBytes);

              string finalHash = System.BitConverter.ToString(destBytes).Replace("-", string.Empty);

              reqIdBase += finalHash + "-";
        }
开发者ID:Katry4,项目名称:Bloob-bloob,代码行数:28,代码来源:Event.cs

示例9: Generate

        public Model Generate()
        {
            int count = 1000;
            Vector3[] v = new Vector3[count];
            Vector3[] r = new Vector3[count];
            Random random = new Random();
            Color[] color = new Color[count];
            float[] m = new float[count];

            v[0] = new Vector3(0,
                    0,
                    0);
            r[0] = new Vector3(0,
                0,
                0);
            m[0] = 1000000000;
            color[0] = Color.white;

            for (int i = 1; i < count; i++)
            {
                v[i] = new Vector3((float)random.NextDouble() * (random.NextDouble() > 0.5 ? 1 : -1),
                    (float)random.NextDouble() * (random.NextDouble() > 0.5 ? 1 : -1),
                    (float)random.NextDouble() * (random.NextDouble() > 0.5 ? 1 : -1));
                r[i] = new Vector3((float)random.NextDouble() * 100,
                    (float)random.NextDouble() * 100,
                    (float)random.NextDouble() * 100);
                m[i] = random.Next(10000, 100000);
                color[i] = Color.yellow;
            }
            Model model = new Model(r, v, m, color);
            model.G = 0.00001f;
            model.dt = 0.005f;
            return model;
        }
开发者ID:anfulu36484,项目名称:GravitatioanlSimulation,代码行数:34,代码来源:ModelGenerator2.cs

示例10: ShuffleChildren

 ///<summary>
 ///Randomizes the position of the Transform's children in the Hierarchy.
 ///Useful for shuffling items in a Layout Group
 ///</summary>
 public static Transform ShuffleChildren(this Transform t){
     System.Random rand = new System.Random();
     for(int i = 0; i < t.childCount; i++){
         t.GetChild(rand.Next(0, t.childCount-1)).SetSiblingIndex(i);
     }
     return t; 
 }
开发者ID:loloop,项目名称:totem-master,代码行数:11,代码来源:TransformGoodies.cs

示例11: ItemSpawnComponent

 public ItemSpawnComponent(ItemManager parent, Environment environment)
     : base(parent, "ItemSpawnComponent")
 {
     this.random = new System.Random();
     this.timeTillSpawn = random.Next(MAX_FREQUENCY - MIN_FREQUENCY) + MIN_FREQUENCY;
     this.environment = environment;
 }
开发者ID:regenvanwalbeek,项目名称:BattleFury,代码行数:7,代码来源:ItemSpawnComponent.cs

示例12: GetRandomSixDigitHexNumber

 public string GetRandomSixDigitHexNumber()
 {
     System.Random random = new System.Random();
     int num = random.Next(1048576, 10066329);
     string hexString = num.ToString("X");
     return hexString;
 }
开发者ID:senseix,项目名称:thinksy_unity_plugin,代码行数:7,代码来源:GameVerificationCode.cs

示例13: SleepRandom

 public ActionResult SleepRandom(int? min, int? max)
 {
     if(!min.HasValue || min.Value < 0) min = 50;
     if(!max.HasValue || max.Value < min.Value) max = min + 200;
     var rand = new System.Random();
     return SleepFor(rand.Next(min.Value, max.Value));
 }
开发者ID:evilDave,项目名称:mvc_testsite,代码行数:7,代码来源:HomeController.cs

示例14: startMenuOverlay

        private bool startMenuOverlay(OverlayRenderer overlayRenderer)
        {
            if (!Misc.Parse(SettingsManager.GetValue("ShowInMenu"), true)) { return false; }

            var objects = GameObject.FindObjectsOfType(typeof(GameObject));
            if (objects.Any(o => o.name == "LoadingBuffer")) { return false; }
            var kerbin = objects.OfType<GameObject>().Where(b => b.name == "Kerbin").LastOrDefault();

            if (kerbin == null)
            {
                Debug.LogWarning("[Kethane] Couldn't find Kerbin!");
                return false;
            }

            overlayRenderer.SetTarget(kerbin.transform);
            overlayRenderer.SetRadiusMultiplier(1.02f);

            var random = new System.Random();
            var colors = new CellMap<Color32>(KethaneData.GridLevel);

            foreach (var cell in Cell.AtLevel(KethaneData.GridLevel))
            {
                var rand = random.Next(100);
                Color32 color;
                if (rand < 16)
                {
                    color = rand < 4 ? new Color32(21, 176, 26, 255) : new Color32(128, 128, 128, 192);
                    foreach (var neighbor in cell.GetNeighbors(KethaneData.GridLevel))
                    {
                        if (random.Next(2) < 1)
                        {
                            colors[neighbor] = color;
                        }
                    }
                }
                else
                {
                    color = new Color32(0, 0, 0, 128);
                }

                colors[cell] = color;
            }

            overlayRenderer.SetCellColors(colors);

            return true;
        }
开发者ID:kjoenth,项目名称:Kethane,代码行数:47,代码来源:MainMenuOverlay.cs

示例15: Start

        void Start()
        {
            Tile tileScript = GetComponent<Tile>();
            SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
            System.Random random = new System.Random(tileScript.TileMap.GetComponent<TileMap>().GetSeedAtPosition(tileScript.TileMapPosition));

            spriteRenderer.sprite = Sprites[random.Next(Sprites.Length)];
        }
开发者ID:devolin,项目名称:gamedev,代码行数:8,代码来源:RandomSprite.cs


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