本文整理汇总了C#中System.Random.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Random.ToString方法的具体用法?C# Random.ToString怎么用?C# Random.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Random
的用法示例。
在下文中一共展示了Random.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LinkButton3_Click
protected void LinkButton3_Click(object sender, EventArgs e)
{
HttpContext.Current.Response.AppendHeader("Content-encoding", "");
Random random = new Random();
imgCaptcha.ImageUrl = imgCaptcha.ImageUrl + "?" + random.ToString();
}
示例2: Main
static void Main(string[] args)
{
try
{
string url = "65.52.224.21:10000";
var fs = File.Create(filename);
fs.Close();
Timer timer = new Timer(5000);
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Start();
for (int i = new Random().Next(0, 1000000); i >= 0; i++)
{
try
{
var server = MongoServer.Create(string.Format("mongodb://{0}/?slaveOk=true", url));
server.Connect();
var db = server.GetDatabase("test");
var collection = db.GetCollection<BsonDocument>("numbers");
collection.Insert(new BsonDocument()
{
{ i.ToString(), @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur venenatis, lectus viverra blandit faucibus, eros risus adipiscing ipsum, at iaculis magna neque in nibh. Nulla venenatis, purus in imperdiet aliquet, ligula ligula gravida lorem, et egestas justo tellus cursus elit. Nam ut metus leo. In et odio et ligula auctor vulputate. Nunc posuere erat at tortor molestie gravida. Vestibulum sodales nunc pharetra tellus aliquam et blandit risus suscipit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin erat leo, eleifend vitae hendrerit sollicitudin, eleifend vel neque. Sed et sapien nunc, at adipiscing dolor. Sed luctus mollis arcu, eu adipiscing risus suscipit nec. Aenean eu elit lacus, in dapibus sem. Aliquam est dui, porta vitae fringilla eget, tristique in neque. Aliquam eget nisl ac tellus sodales viverra. Nam mauris mauris, ornare placerat aliquet id, eleifend et mauris. Fusce iaculis condimentum aliquet. Nunc dictum massa nunc." }
});
insertCount++;
var query = Query.EQ(i.ToString(), @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur venenatis, lectus viverra blandit faucibus, eros risus adipiscing ipsum, at iaculis magna neque in nibh. Nulla venenatis, purus in imperdiet aliquet, ligula ligula gravida lorem, et egestas justo tellus cursus elit. Nam ut metus leo. In et odio et ligula auctor vulputate. Nunc posuere erat at tortor molestie gravida. Vestibulum sodales nunc pharetra tellus aliquam et blandit risus suscipit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin erat leo, eleifend vitae hendrerit sollicitudin, eleifend vel neque. Sed et sapien nunc, at adipiscing dolor. Sed luctus mollis arcu, eu adipiscing risus suscipit nec. Aenean eu elit lacus, in dapibus sem. Aliquam est dui, porta vitae fringilla eget, tristique in neque. Aliquam eget nisl ac tellus sodales viverra. Nam mauris mauris, ornare placerat aliquet id, eleifend et mauris. Fusce iaculis condimentum aliquet. Nunc dictum massa nunc.");
foreach (BsonDocument number in collection.Find(query))
{
var element = number.Elements.ToList()[1];
Console.WriteLine(string.Format("Name: {0} - Value : {1}[...]", element.Name, element.Value.AsString.Substring(0, 40)));
}
}
catch (Exception ex)
{
Console.WriteLine("erreur");
Console.WriteLine(ex.Message);
}
}
}
catch (Exception exx)
{
Console.WriteLine(exx.Message);
}
finally
{
Console.WriteLine("Appuyez sur une touche pour quitter");
Console.ReadLine();
}
}
示例3: CreateNewRoom
public ActionResult CreateNewRoom()
{
var newRoomNumber = new Random()
.ToEnumerable(r => r.Next(100, 10000))
.First(n => this.Db.Rooms.Any(room => room.RoomNumber == n) == false);
var urlOfThisRoom = Url.AppUrl() + Url.Action("Room", new { id = newRoomNumber });
var bitly = Bitly.Default;
var shortUrlOfThisRoom = bitly.Status == Bitly.StatusType.Available ?
#if DEBUG
bitly.ShortenUrl("http://asktheaudiencenow.azurewebsites.net/Room/" + newRoomNumber.ToString()) : "";
#else
bitly.ShortenUrl(urlOfThisRoom) : "";
#endif
var options = new[] {
new Option{ DisplayOrder = 1, Text = "Yes" },
new Option{ DisplayOrder = 2, Text = "No"},
}.ToList();
this.Db.Rooms.Add(new Room
{
RoomNumber = newRoomNumber,
OwnerUserID = this.User.Identity.Name,
Options = options,
Url = urlOfThisRoom,
ShortUrl = shortUrlOfThisRoom
});
this.Db.SaveChanges();
return RedirectToAction("Room", new { id = newRoomNumber });
}
示例4: DiceRoll
public HttpResponseMessage DiceRoll(string triggerState,
[Metadata("Number of Sides", "Number of sides that should be on the die that is rolled")]
int numberOfSides,
[Metadata("Target Number", "Trigger will fire if dice roll is above this number")]
int targetNumber)
{
// Validate configuration
if (numberOfSides <= 0)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest,
"Bad configuration. Dice require 1 or more sides");
}
int lastRoll = 0;
int.TryParse(triggerState, out lastRoll);
int thisRoll = new Random().Next(numberOfSides);
// Roll the dice
if (thisRoll >= targetNumber /* We've hit or exceeded the target */
&& thisRoll != lastRoll /* And this dice roll isn't the same as the last */)
{
// Let the Logic App know the dice roll matched
return Request.EventTriggered(new SamplePollingResult(thisRoll),
triggerState: thisRoll.ToString(),
pollAgain: TimeSpan.FromSeconds(30));
}
else
{
// Let the Logic App know we don't have any data for it
return Request.EventWaitPoll(retryDelay: null, triggerState: triggerState);
}
}
示例5: ZAP
public void ZAP()
{
var score = new Random().Next(32);
Debug.Print("Zapping for " + score);
_queueClient.CreateQueueMessage(score.ToString());
}
示例6: CHOMP
public void CHOMP()
{
var score = new Random().Next(16);
Debug.Print("Chomping for " + score);
_queueClient.CreateQueueMessage(score.ToString());
}
示例7: ProcessRequest
public void ProcessRequest(HttpContext context)
{
try
{
var tokenReportIdentifier = context.Request.QueryString[Constants.KindOfReportParameter];
var reportService = CreateInstanceBasedOnToken(tokenReportIdentifier);
//Retrieve the class name parameters
var classNames = new StringDictionary();
foreach (var styleName in typeof (StyleName).GetFields())
classNames.Add(styleName.Name, context.Request[styleName.GetValue(null).ToString()]);
var textResponse = reportService.getReport(context.Request.QueryString);
//it waits 1 up to 10 seconds
var rnd = new Random(DateTime.Now.Millisecond).Next(1, 7);
Thread.Sleep(rnd*1000);
Log.Debug(GetType(),
"Time loading the report: " + rnd.ToString(CultureInfo.InvariantCulture) + " seconds");
// *** end ***
textResponse = ReportHelper.FormatResultTokens(textResponse, classNames);
if (!String.IsNullOrEmpty(context.Request[Constants.JsonCallbackParameter]))
textResponse = String.Format(CultureInfo.InvariantCulture, "{0}({1});",
context.Request[Constants.JsonCallbackParameter], textResponse);
context.Response.StatusCode = (int) HttpStatusCode.OK;
context.Response.ContentType = "application/json";
context.Response.Write(textResponse);
}
catch (Exception ex)
{
Log.LogException(GetType(), ex);
}
}
示例8: Login_Input
protected int Login_Input()
{
UserLoginStatus loginStatus = new UserLoginStatus();
UserInfo objUserInfo = UserController.ValidateUser(PortalId, tbUsername.Text, tbPassword.Text, "", PortalSettings.PortalName, Request.UserHostAddress, ref loginStatus);
if (loginStatus == UserLoginStatus.LOGIN_SUCCESS || loginStatus == UserLoginStatus.LOGIN_SUPERUSER)
{
UserController.UserLogin(PortalId, objUserInfo, PortalSettings.PortalName, Request.UserHostAddress, false);
if (cbRemember.Checked)
{
// Set settings
int random = new Random().Next();
ModuleController obModule = new ModuleController();
obModule.UpdateModuleSetting(ModuleId, tbUsername.Text, random.ToString());
// Set cookie
HttpCookie obCookie = new HttpCookie(cookie_name());
obCookie.Value = string.Format("{0}_{1}", random, tbUsername.Text);
obCookie.Expires = DateTime.Today.AddMonths(3);
Response.Cookies.Add(obCookie);
obCookie = new HttpCookie("EOFFICE");
obCookie.Value = Request.ApplicationPath;
obCookie.Expires = DateTime.Today.AddYears(1);
obCookie.HttpOnly = false;
Response.Cookies.Add(obCookie);
}
return 1;
}
else
{
lbError.Text = "Tên đăng nhập hoặc Mật khẩu không chính xác";
return 0;
}
}
示例9: Execute
public void Execute(IrcDotNet.IrcClient Client, string Channel, IrcDotNet.IrcUser Sender, string Message)
{
string[] words = Message.Trim().Split(' ');
if (words.Length < 2 || words.Length > 2)
{
Client.LocalUser.SendMessage(Channel, "!random <start> <end>");
return;
}
int start, end;
try
{
start = Convert.ToInt32(words[0]);
end = Convert.ToInt32(words[1]);
}
catch (Exception)
{
Client.LocalUser.SendMessage(Channel, "Numbers please");
return;
}
int random = new Random().Next(start, end + 1);
Client.LocalUser.SendMessage(Channel, random.ToString());
}
示例10: Generatetxnid
public string Generatetxnid()
{
Random rnd = new Random();
string strHash = Generatehash512(rnd.ToString() + DateTime.Now);
//string txnid1 = strHash.ToString().Substring(0, 20);
return strHash.ToString().Substring(0, 20);
}
示例11: ValidateOperation
private bool ValidateOperation()
{
return true;
Thread.Sleep(3000);
var validateResult = new Random().Next(0, 2) == 1 ? true : false;
Console.WriteLine("Thread:" + Thread.CurrentThread.ManagedThreadId + " Validate " + validateResult.ToString());
return validateResult;
}
示例12: LoadPage
public void LoadPage() {
var i1 = new MGMixAndMatchItems();
var i2 = new MGMixAndMatchItems();
var i3 = new MGMixAndMatchItems();
MGMixAndMatch.Get3RandomItems(int.Parse(MMID.Text), out i1, out i2, out i3);
MGMixAndMatchItems correctItem = null;
var correctItemNumber = new Random(DateTime.Now.Millisecond).Next(1, 3);
switch(correctItemNumber) {
case 1:
correctItem = i1;
break;
case 2:
correctItem = i2;
break;
case 3:
correctItem = i3;
break;
}
var difficulty = int.Parse(Difficulty.Text);
if(correctItem != null) {
MMIID.Text = correctItem.MMIID.ToString();
StringBuilder audio = new StringBuilder(MixMatchBasePath);
switch(difficulty) {
case 2:
//medium
lblMixMatch.Text = correctItem.MediumLabel;
audio.AppendFormat("m_{0}.mp3", MMIID.Text);
break;
case 3:
//hard
lblMixMatch.Text = correctItem.HardLabel;
audio.AppendFormat("h_{0}.mp3", MMIID.Text);
break;
default:
lblMixMatch.Text = correctItem.EasyLabel;
audio.AppendFormat("e_{0}.mp3", MMIID.Text);
break;
}
if(System.IO.File.Exists(Server.MapPath(audio.ToString()))) {
lblSound.Text = string.Format(
"<audio controls><source src='{0}' type='audio/mpeg'>Your browser does not support this audio format.</audio>",
VirtualPathUtility.ToAbsolute(audio.ToString()));
pnlAudio.Visible = true;
}
}
Correct.Text = correctItemNumber.ToString();
btn1.ImageUrl = string.Format("{0}{1}.png", MixMatchBasePath, i1.MMIID);
btn2.ImageUrl = string.Format("{0}{1}.png", MixMatchBasePath, i2.MMIID);
btn3.ImageUrl = string.Format("{0}{1}.png", MixMatchBasePath, i3.MMIID);
}
示例13: timer_tick
private void timer_tick(object sender, object e)
{
Random rand1 = new Random();
answer = rand1.Next(1, 75);
List<Data> data = new List<Data>();
data.Add(new Data() { Category = rand1.ToString(), Value = answer });
this.Graph1.DataContext = data;
}
示例14: RandMD5
public string RandMD5()
{
var res = String.Empty;
var source = new Random();
using (MD5 md5Hash = MD5.Create())
{
res = GetMd5Hash(md5Hash, source.ToString());
}
return res;
}
示例15: createPk
public object createPk()
{
int rangdomNum=new Random().Next(1000,9999);
string pk = string.Format("{0}{1}"
, DateTime.Now.ToString("yyyyMMddHHmmss")
,rangdomNum.ToString()
);
Thread.Sleep(50);
return pk;
}