public RandomValue() { RandNum = RandomNumberGenerator.Create(); R = new Random(RandNum.GetHashCode()); this.RandomVal = R.NextDouble(); }
private int i = 0;//this is in seconds can be switched for later use if some other itme is prefered //private float coolDownTimer=0; //spawner location randomise which enemy is spawned and where void FixedUpdate() { if (i == 0) { int rand = RandNum.GetRandomNumber(0, 99); if (rand < 20) { Instantiate(SmallEnemyPrefab, new Vector3(transform.position.x, transform.position.y + 3f, transform.position.z), Quaternion.identity); } else if (rand > 20 && rand < 40) { Instantiate(MedEnemyPrefab, new Vector3(transform.position.x, transform.position.y + 3f, transform.position.z), Quaternion.identity); } else if (rand > 40 && rand < 45) { Instantiate(LargeEnemyPrefab, new Vector3(transform.position.x, transform.position.y + 3f, transform.position.z), Quaternion.identity); } else if (rand > 45 && rand < 70) { Instantiate(TeleExplosion, new Vector3(transform.position.x, transform.position.y + 3f, transform.position.z), Quaternion.identity); } else if (rand > 70 && rand < 90) { Instantiate(shooter, new Vector3(transform.position.x, transform.position.y + 3f, transform.position.z), Quaternion.identity); } else { } i++; } }
//spawner location randomise which enemy is spawned and where void FixedUpdate() { if (i == 0) { int rand = RandNum.GetRandomNumber(0, 99); if (rand < 20) { Instantiate(LazerGun, transform.position, Quaternion.identity); } else if (rand > 20 && rand < 40) { Instantiate(SpeedBoost, transform.position, Quaternion.identity); } else if (rand > 40 && rand < 60) { Instantiate(Teleport, transform.position, Quaternion.identity); } else if (rand > 60 && rand < 80) { Instantiate(Invincibility, transform.position, Quaternion.identity); } else { Instantiate(OneUp, transform.position, Quaternion.identity); } i++; } }
public override void Process() { if (Active) { if (decisionTicks == 0) { xVector = RandNum.Integer(-1, 2); yVector = RandNum.Integer(-1, 2); decisionTicks = RandNum.Integer(10, 30); } Move(xVector, yVector); var positions = GetPositions(); var inWater = positions.Any(p => p.HasWater); if (inWater) { xVector = -xVector; yVector = -yVector; } foreach (var p in positions) { p.EatFlora(); } decisionTicks--; } }
public async Task <ActionResult> DeleteConfirmed(int id) { RandNum randNum = await db.RandNums.FindAsync(id); db.RandNums.Remove(randNum); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
private void Throw() { if (!_thrown) { Vector3 playerPosition = _playerRb.transform.position; Instantiate(presents[RandNum.GetNumTo(4)], new Vector3(playerPosition.x, (playerPosition.y + 0.5f), playerPosition.y), Quaternion.identity); _thrown = true; StartCoroutine(throwTimer()); } }
/// <summary> /// 按时间加随机数生成文件名 /// </summary> /// <param name="FileExt">文件后缀名</param> /// <returns></returns> public string TimeFileName(string FileExt) { int RandNum; string PhotoName; Random rnd = new Random(); RandNum = rnd.Next(1, 99);//生成一个99以内的随机数 PhotoName = DateTime.Now.ToString("yyyyMMddHHmmssffffff") + RandNum.ToString() + FileExt; return(PhotoName); }
public async Task <ActionResult> Edit([Bind(Include = "Id,LgRandNum,SmRandNum")] RandNum randNum) { if (ModelState.IsValid) { db.Entry(randNum).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(randNum)); }
public async Task <ActionResult> Create([Bind(Include = "Id,LgRandNum,SmRandNum")] RandNum randNum) { if (ModelState.IsValid) { db.RandNums.Add(randNum); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(randNum)); }
// GET: RandNums/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RandNum randNum = await db.RandNums.FindAsync(id); if (randNum == null) { return(HttpNotFound()); } return(View(randNum)); }
/// <summary> /// 按时间加随机数生成文件名 /// </summary> /// <param name="fileIndex">文件索引</param> /// <returns></returns> public string TimeFileName(int fileIndex) { int RandNum; string fileName; System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; if (fileIndex < 0 || fileIndex >= files.Count) { files = null; return(""); } System.Web.HttpPostedFile file = files[fileIndex]; Random rnd = new Random(); RandNum = rnd.Next(1, 99);//生成一个99以内的随机数 fileName = DateTime.Now.ToString("yyyyMMddHHmmssffffff") + RandNum.ToString() + System.IO.Path.GetExtension(file.FileName); file = null; files = null; return(fileName); }
public IActionResult Index() { HttpContext.Session.SetString("Random", RandNum.GetRandomAlphaNumeric()); string LocalVariable = HttpContext.Session.GetString("Random"); ViewBag.num = LocalVariable; if (HttpContext.Session.GetInt32("counter") == null) { HttpContext.Session.SetInt32("counter", 1); int?count = HttpContext.Session.GetInt32("counter"); ViewBag.count = count; return(View()); } else { HttpContext.Session.SetInt32("counter", (int)(HttpContext.Session.GetInt32("counter") + 1)); int?count = HttpContext.Session.GetInt32("counter"); ViewBag.count = count; } return(View()); }
public bool CreateMoons(IDbConnection connection) { var moonType = PlanetoidSubTypes.Moon.ToString(); var moonTextureTypes = _gameTypeService.GetTextures(connection, MapTypes.Satellite.ToString(), moonType); var moonTextIds = moonTextureTypes.Select(i => i.Id).ToList(); var moonTextUsedIds = new List <short>(); var planetGeomety = _getPlanetCollection(connection); var planetsDetail = _getPlanetDetailCollection(connection); var parentId = 0; double firstPlanetRadius = 0; var mincoef = 4; var planetCount = planetGeomety.Count; for (var i = 0; i < planetCount; i++) { var planet = planetGeomety[i]; var detailPlanet = planetsDetail[i]; if (parentId != planet.Parent) { parentId = planet.Parent; firstPlanetRadius = planet.Radius; } var parentRadius = planet.Radius; var minMoonRadius = firstPlanetRadius / mincoef; var minMoonOrbit = parentRadius + (1.5 * minMoonRadius); if (detailPlanet.MoonCount == 0) { continue; } for (var moonIndex = 0; moonIndex < detailPlanet.MoonCount; moonIndex++) { var ki = Math.Pow(Factor, moonIndex + 1); //"DT-CA-1-3" var moonName = planet.NativeName + "-" + (moonIndex + 1); var maxRadius = parentRadius / 4; var moonRadius = RandNum.NextDouble(minMoonRadius, maxRadius); //13.72 var moonCurrOrbit = minMoonOrbit * ki; var moonTextureId = GameTypeHalper.GetRandomTypeFromUsedTyps(moonTextIds, ref moonTextUsedIds); var geometryMoon = _moonService.AddOrUpdateGeometryMoon(connection, new GGeometryMoonDataModel { GalaxyId = planet.GalaxyId, SectorId = planet.SectorId, SystemId = planet.SystemId, PlanetId = planet.Id, Radius = Math.Round(moonRadius, 4), Orbit = Math.Round(moonCurrOrbit, 4), OrbitPosition = (byte)Rand.Next(0, Tes), TypeId = (byte)PlanetoidSubTypes.Moon, AxisAngle = _getRandomAngle(FactorAngle), OrbitAngle = _getRandomAngle(FactorAngle), TextureTypeId = moonTextureId, }); var detailMoon = _createMoonDetail(connection, geometryMoon.Id, moonName); var dm = _moonService.AddOrUpdateDetailMoon(connection, detailMoon); if (dm == null || dm.Id == 0) { throw new NotImplementedException("moon didn't created"); } } } return(true); }