本文整理汇总了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;
}
}
示例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);
}
示例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);
});
}
示例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));
}
示例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);
});
}
示例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);
}
示例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));
}
示例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 + "-";
}
示例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;
}
示例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;
}
示例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;
}
示例12: GetRandomSixDigitHexNumber
public string GetRandomSixDigitHexNumber()
{
System.Random random = new System.Random();
int num = random.Next(1048576, 10066329);
string hexString = num.ToString("X");
return hexString;
}
示例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));
}
示例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;
}
示例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)];
}