public void BoundedRandomInt() { const int LOWER = -17; const int UPPER = 24; var rand = RandomHelpers.RandomInt(LOWER, UPPER); Assert.IsTrue(LOWER <= rand); Assert.IsTrue(UPPER >= rand); }
public string SaveFileIfExist(string name) { if (string.IsNullOrWhiteSpace(name)) { return(string.Empty); } IFormFile file = this._httpContextAccessor.HttpContext.Request.Form.Files.GetFile(name); if (file == null) { return(string.Empty); } string extension = MimeHelpers.GetExtension(file.ContentType); if (string.IsNullOrWhiteSpace(extension)) { extension = Path.GetExtension(file.FileName); } Console.WriteLine(file.ContentType); string relativePath = string.Format("\\Upload\\{0}\\{1}{2}{3}", DateTime.Now.ToString("yyyyMM"), DateTime.Now.ToString("yyyyMMddHHmmssfff"), RandomHelpers.RandomInt(1000, 9999), extension ).ToLower(); string absolutePath = this._hostingEnvironment.WebRootPath + relativePath; PathHelpers.EnsureParentDirectory(absolutePath); Stream stream = file.OpenReadStream(); //对大于1MB的图片进行压缩,最大宽度为1024像素 //if (MimeUtils.IsImage(file.ContentType) && file.Length > 1024 * 1000) //{ // ThumbUtils.SendSmallImage(stream, absolutePath, 1024, 1024); //} //else { byte[] buffer = new byte[file.Length]; stream.Read(buffer, 0, buffer.Length); System.IO.File.WriteAllBytes(absolutePath, buffer); } stream.Close(); string host = GetHostUrl(this._httpContextAccessor.HttpContext); return(host + relativePath.Replace("\\", "/")); }
void DrawRandomClumpsOfRocksOnMap(TerrainMap map) { if (_useRandomRocks) { const int SPREAD = 4; int r = map.Cellwidth(); int k = RandomHelpers.RandomInt(50, 150); for (int p = 0; p < k; p++) { int i = RandomHelpers.RandomInt(0, r - SPREAD); int j = RandomHelpers.RandomInt(0, r - SPREAD); int c = RandomHelpers.RandomInt(0, 10); for (int q = 0; q < c; q++) { int m = RandomHelpers.RandomInt(0, SPREAD); int n = RandomHelpers.RandomInt(0, SPREAD); map.SetMapBit(i + m, j + n, true); } } } }
void RandomizeDigits() { UIDigitsDemo.Digits = (uint)RandomHelpers.RandomInt(100); UIDigitDemo.Digit = (uint)RandomHelpers.RandomInt(10); }
public Texture2D GetRandomLoadedTexture() { return(LoadedTextures[RandomHelpers.RandomInt(LoadedTextures.Count)]); }