當前位置: 首頁>>代碼示例>>C#>>正文


C# Random.ToString方法代碼示例

本文整理匯總了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();
        }
開發者ID:g992com,項目名稱:esb,代碼行數:7,代碼來源:Login.aspx.cs

示例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();
            }
        }
開發者ID:smonteil,項目名稱:azuremongospare,代碼行數:53,代碼來源:Program.cs

示例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 });
        }
開發者ID:darkcrash,項目名稱:signalYN,代碼行數:32,代碼來源:DefaultController.cs

示例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);

            }

        }
開發者ID:ninocrudele,項目名稱:TRex,代碼行數:34,代碼來源:PollingTriggerSampleController.cs

示例5: ZAP

        public void ZAP()
        {
            var score = new Random().Next(32);

            Debug.Print("Zapping for " + score);
            _queueClient.CreateQueueMessage(score.ToString());
        }
開發者ID:AndyCross,項目名稱:netmfazurequeue,代碼行數:7,代碼來源:SharkWithAFreakinLaser.cs

示例6: CHOMP

        public void CHOMP()
        {
            var score = new Random().Next(16);

            Debug.Print("Chomping for " + score);
            _queueClient.CreateQueueMessage(score.ToString());
        }
開發者ID:AndyCross,項目名稱:netmfazurequeue,代碼行數:7,代碼來源:SharkWithAFreakinLaser.cs

示例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);
            }
        }
開發者ID:Learion,項目名稱:BruceToolSet,代碼行數:35,代碼來源:RetrieveReport.ashx.cs

示例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;
     }
 }
開發者ID:chungnt88,項目名稱:DesktopModules,代碼行數:32,代碼來源:Login.ascx.cs

示例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());
        }
開發者ID:code-n-beer,項目名稱:SimoBot,代碼行數:25,代碼來源:RandomFeature.cs

示例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);
        }
開發者ID:Burima,項目名稱:LYSApp,代碼行數:8,代碼來源:PaymentController.cs

示例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;
        }
開發者ID:Robin2009,項目名稱:TPLSamples,代碼行數:9,代碼來源:AsyncAwaitSample9.cs

示例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);
        }
開發者ID:haraldnagel,項目名稱:greatreadingadventure,代碼行數:57,代碼來源:MGMixMatchPlay.ascx.cs

示例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;
        }
開發者ID:saturdaysz,項目名稱:park1,代碼行數:9,代碼來源:MainPage.xaml.cs

示例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;
 }
開發者ID:vladdyslav,項目名稱:arbitraryportable,代碼行數:10,代碼來源:ArbitraryBaseTests.cs

示例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;
 }
開發者ID:uhealin,項目名稱:toyz-toyz4net,代碼行數:10,代碼來源:BaseModel.cs


注:本文中的System.Random.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。