Next() public méthode

public Next ( ) : uint
Résultat uint
	public float computeCount() {
		Random rnd = new Random();
		float val = rnd.Next(4);
		if(val == 2) // insert a random spike
			return rnd.Next(40);
		return rnd.Next(10);
	}
 private void performanceScale(CCSprite pSprite)
 {
     Random random = new Random();
     CCSize size = CCDirector.sharedDirector().getWinSize();
     pSprite.position = new CCPoint((random.Next() % (int)size.width), (random.Next() % (int)size.height));
     pSprite.scale = random.Next() * 100 / 50;
 }
        public void reset()
        {
            Random random = new Random();
            int localtag = 0;
            localtag++;

            // TO TRIGGER THE BUG:
            // remove the itself from parent from an action
            // The menu will be removed, but the instance will be alive
            // and then a new node will be allocated occupying the memory.
            // => CRASH BOOM BANG
            CCNode node = getChildByTag(localtag - 1);
            CCLog.Log("Menu: %p", node);
            removeChild(node, false);
            //	[self removeChildByTag:localtag-1 cleanup:NO];

            CCMenuItem item1 = CCMenuItemFont.itemFromString("One", this, menuCallback);
            CCLog.Log("MenuItemFont: %p", item1);
            CCMenuItem item2 = CCMenuItemFont.itemFromString("Two", this, menuCallback);
            CCMenu menu = CCMenu.menuWithItems(item1, item2);
            menu.alignItemsVertically();

            float x = random.Next() * 50;
            float y = random.Next() * 50;
            menu.position = CCPointExtension.ccpAdd(menu.position, new CCPoint(x, y));
            addChild(menu, 0, localtag);

            //[self check:self];
        }
Exemple #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //加载页面时初始化支付需要的业务明文参数

        orderAmount.Text = "2";//默认的交易金额

        Random ra = new Random();
        traderOrderID.Text = "1234567" + 50 * ra.Next();//商户订单号

        identityID.Text = "user_" + 50 * ra.Next();//用户身份标识
        identityType.Text = "2";//用户身份标识类型,0为IMEI,1为MAC,2为用户ID,3为用户Email,4为用户手机号,5为用户身份证号,6为用户纸质协议单号
        userIP.Text = getIp();//获取用户IP地址
        userUA.Text = Request.UserAgent;//获取用户UA

        terminalType.Text = "3";//终端类型,0、IMEI;1、MAC;2、UUID;3、other,如果终端类型未知的话,那么就传other
        terminalID.Text = "nothing";//终端类型未知,终端标识可以传任意字符串

        productCatalog.Text = "1";//1代表虚拟商品,商品类别必须与协议保持一致。商品类别编码请见http://mobiletest.yeepay.com/file/doc/pubshow?doc_id=14#hm_27。
        productName.Text = "玉米加农炮";//商品名称
        productDesc.Text = "植物大战僵尸道具";//商品描述

        fcallbackURL.Text = "http://mobiletest.yeepay.com/demo/pay/callback";//支付成功后商户前台提供的回调的地址,fcallbackURL.Text = "http://mobiletest.yeepay.com/demo/pay/callback";

        callbackURL.Text = "http://mobiletest.yeepay.com/demo/pay/callback";//支付成功后商户后台提供的回调的地址,fcallbackURL.Text = "http://mobiletest.yeepay.com/demo/pay/callback";
    }
Exemple #5
0
        static void Main(string[] args)
        {
            //using (var w = new GameWindow())
            //{
            //    w.Open();
            //}

            var bm = Bitmap32.Load(File.ReadAllBytes("..\\..\\Sample3.png"));

            var random = new Random();
            //var bm = new Bitmap32(640, 480);
            var rd = new BasicRenderer32(bm);
            
            //rd.Clear(new Color32(0x20, 0x20, 0x20, 0xFF));

            rd.FillColor = new Color32(0xFF, 0x00, 0x00, 0x30);
            for (int i = 0; i < 100; i++)
            {
                var r = random.Next(50) + 10;
                var x = random.Next(bm.Width - r * 2) + r;
                var y = random.Next(bm.Height - r * 2) + r;

                rd.SolidElipse(
                    x, y, r, r
                );
            }

            //File.WriteAllBytes("out.png", bm.Save());

            DisplayWindow.Show(bm);

            //bm.Save("out.png");

            //new Bitmap32(bm, 0, 0, 128, 128).Save("out2.png");
        }
        [TestMethod]        // Handling Request on Server
        public void WriteSingleRegisterPDU_LifeCycle()
        {
            var RandomGen = new Random();

            int Address = RandomGen.Next(MinAddress, MaxAddress);
            var Value = RandomGen.Next(0xFFFF);

            var Server = new BaseModbusServer();


            Server.AddHoldingRegister(Address);

            var ClientPDU = new WriteSingleRegisterPDU(Address, Value);
            var Request = ClientPDU.BuildRequest();

            var ServerPDU = new WriteSingleRegisterPDU();
            ServerPDU.CheckRequest(Request);

            Assert.AreEqual(Address, ServerPDU.StartingAddress, "Whong Address recognition in CheckRequest");

            ServerPDU.Handle(Server);
            Assert.AreEqual(Value, ServerPDU.Value, "Whong Address recognition in CheckRequest");

            ClientPDU.CheckResponse(ServerPDU.BuildResponse());
            Assert.AreEqual(Value, ClientPDU.Value, "Whong Address recognition in CheckRequest");
        }
Exemple #7
0
    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        SqlConnection vid = new SqlConnection("Data Source=(local);Initial Catalog=Ring;Integrated Security=True");
        {
            Random rnd = new Random();
            SqlCommand orders = new SqlCommand("INSERT INTO dbo.orders (email,order_ID,month,year,jewel_ID,price,credit_Card) VALUES (@email,@order_ID,@month,@year,@jewel_ID,@price,@credit_Card)", vid);
            orders.Parameters.AddWithValue("@email", Session["username"]);
            int holder = rnd.Next(10000000,99999999);
            orders.Parameters.AddWithValue("@price", ddlPrice.Text);
            orders.Parameters.AddWithValue("@jewel_ID", ddlJewel.Text);
            holder = rnd.Next(10000000, 99999999);
            orders.Parameters.AddWithValue("@order_ID", holder.ToString());
            orders.Parameters.AddWithValue("@month", DateTime.Now.Month.ToString());
            orders.Parameters.AddWithValue("@year", DateTime.Now.Year.ToString());
            holder = rnd.Next(10000000, 99999999);
            orders.Parameters.AddWithValue("@credit_Card", holder.ToString());
            holder = rnd.Next(10000000, 99999999);
            SqlCommand inventory = new SqlCommand("UDATE dbo.Inventory SET jewel_ID='"+holder+"'WHERE jewel_ID='"+ ddlJewel.Text+"'", vid);
            vid.Open();

            orders.ExecuteNonQuery();
            inventory.ExecuteNonQuery();
            vid.Close();

            if (IsPostBack)
            {
                Server.Transfer("Account.aspx", true);
            }
        }
    }
        public void GetCombinations()
        {
            //given a input
            //
            Random rnd = new Random();
            int n = rnd.Next(2, 10);
            int k = rnd.Next(n + 1); // RND boundaries are exclusive so n+1 will allow inclusive boundaries

            // Get combinations
            //
            var combination = generator.GetCombinations((uint)n, (uint)k);

            // Get Control value
            //
            var controlValue = GetControlCombinations(n, k);

            //do validate if output matches expected value
            //
            Assert.AreEqual<uint>(
                (uint)(controlValue),
                combination,
                "C({0},{1}) was computed as {2} instead of expected value of {3}",
                n,
                k,
                combination,
                controlValue);
        }
    static string[] RandomStringArray()
    {
        Random rand = new Random();
        int len = rand.Next(3, 10); // [3;10)
        string[] stringArr = new string[len];

        // let's build the words observing the frequency of the letters in English
        // so for example the vowels will appear more often
        // http://www.oxforddictionaries.com/words/what-is-the-frequency-of-the-letters-of-the-alphabet-in-english
        double[] frequencies = { 0.002, 0.004, 0.007, 0.010, 0.020, 0.031, 0.044, 0.061, 0.079, 0.100, 0.125, 0.155, 0.185, 0.217, 0.251, 0.287, 0.332, 0.387, 0.444, 0.511, 0.581, 0.652, 0.728, 0.803, 0.888, 1.000, };
        char[] letters = { 'q', 'j', 'z', 'x', 'v', 'k', 'w', 'y', 'f', 'b', 'g', 'h', 'm', 'p', 'd', 'u', 'c', 'l', 's', 'n', 't', 'o', 'i', 'r', 'a', 'e', };

        for (int i = 0; i < len; i++)
        {
            int wordLen = rand.Next(1, 10); // determines the length of the current string
            string word = string.Empty;
            for (int j = 0; j < wordLen; j++)
            {
                double frequency = rand.Next(2, 1000) / 1000d; // [0.002;0.999]
                int index = Array.BinarySearch(frequencies, frequency);
                if (index < 0) index = ~index;
                char letter = letters[index];
                word += letter;
            }
            stringArr[i] = word;
        }
        return stringArr;
    }
    static void Main()
    {
        Matrix first = new Matrix(5, 5);
        Matrix second = new Matrix(5, 5);

        Random random = new Random();

        for (int rows = 0; rows < first.rows; rows++)
        {
            for (int columns = 0; columns < first.columns; columns++)
            {
                first[rows, columns] = random.Next(-150, 150);
                second[rows, columns] = random.Next(-150, 150);
            }
        }
        Console.WriteLine("Matrix 1:");
        Console.WriteLine(first);

        Console.WriteLine("Matrix 2:");
        Console.WriteLine(second);

        Console.WriteLine("Result after addition:");
        Console.WriteLine(first + second);

        Console.WriteLine("Result upon substraction:");
        Console.WriteLine(first - second);

        Console.WriteLine("Matrices multiplication:");
        Console.WriteLine(first * second);
    }
        public static IEnumerable<object[]> AddMonths_TestData()
        {
            TaiwanCalendar calendar = new TaiwanCalendar();
            Random random = new Random(-55);

            DateTime randomDateTime = TaiwanCalendarUtilities.RandomDateTime();
            if ((calendar.MaxSupportedDateTime.Year - randomDateTime.Year - 1911) > 1000)
            {
                yield return new object[] { randomDateTime, random.Next(1, 1000 * 12) };
            }
            else
            {
                yield return new object[] { randomDateTime, random.Next(1, (calendar.MaxSupportedDateTime.Year - randomDateTime.Year - 1911) * 12) };
            }

            if ((calendar.MinSupportedDateTime.Year - randomDateTime.Year) < -1000)
            {
                yield return new object[] { randomDateTime, random.Next(-1000 * 12, 0) };
            }
            else
            {
                yield return new object[] { randomDateTime, random.Next((calendar.MinSupportedDateTime.Year - randomDateTime.Year) * 12, 0) };
            }

            yield return new object[] { calendar.MaxSupportedDateTime, 0 };
            yield return new object[] { calendar.MinSupportedDateTime, 0 };
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        int x, y;
        string strValidation = null;
        rnd = new Random();
        Response.ContentType = "image/jpeg";
        Response.Clear();
        Response.BufferOutput = true;
        strValidation = GenerateString();
        Session["strValidation"] = strValidation;
        Font font = new Font("Arial", (float)rnd.Next(17, 20));

        Bitmap bitmap = new Bitmap(200, 50);
        Graphics gr = Graphics.FromImage(bitmap);
        gr.FillRectangle(Brushes.LightGreen, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
        gr.DrawString(strValidation, font, Brushes.Black, (float)rnd.Next(70), (float)rnd.Next(20));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
        for (x = 0; x < bitmap.Width; x++)
            for (y = 0; y < bitmap.Height; y++)
                if (rnd.Next(4) == 1)
                    bitmap.SetPixel(x, y, Color.LightGreen);
        font.Dispose();
        gr.Dispose();
        bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
        bitmap.Dispose();
    }
Exemple #13
0
    public static void Main(Client client)
    {
        string spellName = "adevo mas hur";
        ushort spellMana = 180;
        Random rand = new Random();

        while (true)
        {
            Thread.Sleep(rand.Next(1000 * 10, 1000 * 15));

            if (client.Player.Mana >= spellMana && client.Player.ManaPercent >= 80)
            {
                client.Player.MakeRune(spellName, spellMana);
                Thread.Sleep(rand.Next(1000 * 2, 1000 * 5));
            }
            foreach (ushort id in client.ItemList.Food.All)
            {
                Item food = client.Inventory.GetItem(id);
                if (food != null)
                {
                    food.Use();
                    Thread.Sleep(rand.Next(1000 * 2, 1000 * 6));
                    break;
                }
            }
        }
    }
    void NewSpawnCopArrest(Ped player)
    {
        //So is this from your mod? Provide proof and I'll credit you. Someone sent me this code without any source.
        //I also edited it a bit

        Random r = new Random();
        GTA.Math.Vector3 spawnLoc = player.Position + new Vector3((r.Next(0, 30) / 10), (r.Next(0, 30) / 10), 0);

        List<string> model_names = new List<string>();

        model_names.Add("s_f_y_cop_01");
        model_names.Add("s_m_m_snowcop_01");
        model_names.Add("s_m_y_cop_01");
        model_names.Add("s_m_y_hwaycop_01");
        model_names.Add("csb_cop");

        Ped peds = GTA.World.CreatePed(model_names[r.Next(0, model_names.Count)], spawnLoc);

        peds.Task.ClearAllImmediately();

        peds.Weapons.Give(WeaponHash.Pistol, 9999, true, true);
        peds.Weapons.Give(WeaponHash.Nightstick, 9999, true, true);

        peds.CanRagdoll = false;
        peds.Task.FightAgainst(player);

        peds.Armor = 90;
    }
Exemple #15
0
    public static void Main()
    {
        Stopwatch watch = new Stopwatch();
        Random rand = new Random();
        watch.Start();
        for (int i = 0; i < iterations; i++)
            DayOfYear1(rand.Next(1, 13), rand.Next(1, 29));
        watch.Stop();
        Console.WriteLine("Local array: " + watch.Elapsed);
        watch.Reset();
        watch.Start();
        for (int i = 0; i < iterations; i++)
            DayOfYear2(rand.Next(1, 13), rand.Next(1, 29));
        watch.Stop();
        Console.WriteLine("Static array: " + watch.Elapsed);

        // trying to modify static int []
        daysCumulativeDays[0] = 18;
        foreach (int days in daysCumulativeDays)
        {
            Console.Write("{0}, ", days);
        }
        Console.WriteLine("");

        // MY_STR_CONST = "NOT CONST";
    }
Exemple #16
0
 static void Main()
 {
     int n;
     int[][] mas;
     Console.WriteLine("¬ведите кол-во человек ");
     n=Console.Read();
     mas = new int[n][];
     Random r=new Random();
     r.Next(n);
     for(int i=0; i<n; i++)
     {
         mas[i] = new int[n];
         for (int j=0; j<n; j++)
         {
             mas[i][j]=r.Next();
         }
     }
     for(int i=0; i<n; i++)
     {
         for (int j=0; j<n; j++)
         {
             Console.Write(" "+mas[i][j]);
         }
         Console.WriteLine();
     }
     Console.Read();
 }
    public string[] GetCompletionList(string prefixText, int count)
    {
        if (count == 0)
        {
            count = 10;
        }

        if (prefixText.Equals("xyz"))
        {
            return new string[0];
        }

        Random random = new Random();
        List<string> items = new List<string>(count);
        for (int i = 0; i < count; i++)
        {
            char c1 = (char) random.Next(65, 90);
            char c2 = (char) random.Next(97, 122);
            char c3 = (char) random.Next(97, 122);

            items.Add(prefixText + c1 + c2 + c3);
        }

        return items.ToArray();
    }
    static void Main()
    {
        /* Write a program that finds in given array of integers a sequence of given sum S (if present).
         * Example:	 {4, 3, 1, 4, 2, 5, 8}, S=11  {4, 2, 5} */

        Console.Write("Enter array lenght (or 0 for array autogeneration): ");
        int n = int.Parse(Console.ReadLine());
        int[] arr;
        if (n == 0)
        {
            Random rnd = new Random();
            n = rnd.Next(10, 20);
            arr = new int[n];
            Console.WriteLine("Generated N is: {0}", n);
            Console.WriteLine("Generated array is:");
            for (int i = 0; i < n; i++)
            {
                arr[i] = rnd.Next(18) - 9;
                Console.Write("{0,3}", arr[i]);
            }
            Console.WriteLine();
        }
        else
        {
            arr = new int[n];
            for (int i = 0; i < n; i++)
            {
                Console.Write("Element {0}: ", i + 1);
                arr[i] = int.Parse(Console.ReadLine());
            }
        }
        Console.Write("Enter sum to search for: ");
        int sum = int.Parse(Console.ReadLine());
        Console.WriteLine();

        // input is done

        bool noSolution = true;
        int allSum = 0;

        for (int i = 0; i < n; i++) // start form first element to end of array
        {
            allSum = allSum + arr[i]; // sum of a[0]+a[1]+...+a[i];
            int currSum = allSum;
            for (int j = 0; j <= i; j++) // start from first element to i-th element
            {
                if (currSum == sum) // is currnet sum = sum?
                {
                    Console.Write("Sum = {0} ->", sum);
                    for (int k = j; k <= i; k++) //yes - print sequence a[j]...a[i]
                        Console.Write("{0,3}", arr[k]);
                    Console.WriteLine();
                    noSolution = false;
                }
                currSum = currSum - arr[j]; // subtract a[j] from sum a[j]...a[i];
            }
        }
        if(noSolution)
            Console.WriteLine("No sequence with sum of {0}.",sum);
    }
        private static JToken CreateJToken(Random rndGen, int depth)
        {
            if (rndGen.Next() < CreatorSettings.NullValueProbability)
            {
                return null;
            }

            if (depth < MaxDepth)
            {
                switch (rndGen.Next(10))
                {
                    case 0:
                    case 1:
                    case 2:
                        // 30% chance to create an array
                        return CreateJArray(rndGen, depth);
                    case 3:
                    case 4:
                    case 5:
                        // 30% chance to create an object
                        return CreateJObject(rndGen, depth);
                    default:
                        // 40% chance to create a primitive
                        break;
                }
            }

            return CreateJsonPrimitive(rndGen);
        }
Exemple #20
0
    public static void Main(string[] args)
    {
        int T = 6;
        int N = int.Parse(args[0]);
        int Q = int.Parse(args[1]);

        Random rand = new Random();
        int MAX_VALUE = 32768 + 1;

        Console.WriteLine(T);

        for(; T > 0; T--){
            Console.WriteLine("{0} {1}", N, Q);
            for(int i = 0; i < N; i++){
                if(i != 0) Console.Write(' ');
                Console.Write(rand.Next(0, MAX_VALUE));
            }
            Console.WriteLine();

            for(int i = 0; i < Q; i++){
                int a = rand.Next(0, MAX_VALUE);
                int p = rand.Next(1, N + 1);
                int q = rand.Next(p, N + 1);

                Console.WriteLine("{0} {1} {2}", a, p, q);
            }
        }
    }
    private static void Main()
    {
        // Deklarations
        int result = -1;
        Random rand = new Random();
        int lenghtOfArray = rand.Next(10, 20);
        int[] arrayOfInteger = new int[lenghtOfArray]; // Enter array here and comment down (line 42)

        //arrayOfInteger = { 13, 14, 15, 16, 0, 1, 2, 3, 17, 18, 19, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
        //arrayOfInteger = {10, 8, -7, -10, -6, 1};
        //{ 2, 3, -6, -1, 2, -1, 6, 4, -8, 8 };
        //{4, 3, 1, 4, 2, 5, 8}{ -4, 6, -7, 8, 6, -10, -3, 0 };
        //{ 2, 1, 2, 4, 3, 5, 2, 6 };9 0 6 -10 4 2 10
        for (int i = 0; i < arrayOfInteger.Length; i++)
        {
            arrayOfInteger[i] = rand.Next(-5, 5); // comment if enter hardcore array
            Console.Write(arrayOfInteger[i] + " ");
        }
        Console.WriteLine();

        // Solution
        result = CheckNeighbors(arrayOfInteger);
        if (result == -1)
        {
            Console.WriteLine("No bigger than its neighbors");
        }
        else
        {
            Console.WriteLine("{0} is bigger than its neighbors; index: {1}", arrayOfInteger[result], result);
        }
    }
    void NewSpawnTaserGuy(Ped player)
    {
        //So is this from your mod? Provide proof and I'll credit you. Someone sent me this code without any source.
        //I also edited it a bit
        Random r = new Random();
        GTA.Math.Vector3 spawnLoc = player.Position + new Vector3((r.Next(0, 30) / 10), (r.Next(0, 30) / 10), 0);

        List<string> model_names = new List<string>();

        model_names.Add("a_m_m_tramp_01");
        model_names.Add("a_f_m_trampbeac_01");
        model_names.Add("a_m_m_trampbeac_01");
        model_names.Add("s_m_y_robber_01");
        model_names.Add("a_f_m_beach_01");
        model_names.Add("a_m_m_beach_01");
        model_names.Add("a_m_m_beach_02");

        Ped peds = GTA.World.CreatePed(model_names[r.Next(0, model_names.Count)], spawnLoc);

        peds.Weapons.Give(WeaponHash.StunGun, 1, true, true);

        peds.CanRagdoll = false;
        peds.Task.FightAgainst(player);

        peds.Armor = 90;
    }
Exemple #23
0
 // You and me are gonna bing!
 public void RollDice()
 {
     int roll;
     Random rnd = new Random();
     roll = rnd.Next(1, 6) + rnd.Next(1, 6);
     FindRewards(roll);
 }
        /// <summary>
        /// Generate a tree with a given segment ID.
        /// </summary>
        /// <param name="depth">The depth of the tree.</param>
        /// <param name="maxChildren">The maximum number of children nodes allowed.</param>
        /// <param name="maxValue"> The maximum value allowed for the node's metrics.</param>
        /// <param name="segmentID">The ID to segment to which the leaves belong.</param>
        /// <param name="name">The name of the node (for making node names).</param>
        /// <param name="random">A random number generator for controlling tree generation.</param>
        /// <returns>A SegmentNode representing the root of the tree.</returns>
        private SegmentNode GenerateTree(int depth, int maxChildren, int maxValue, int segmentID, string name, Random random)
        {
            SegmentNode node = new SegmentNode();
            node.Name = name;

            if (depth <= 0)
            {
                node.Value = random.Next(1, maxValue);
                node.Value2 = random.Next(1, maxValue);
                node.Segment = segmentID;
                node.Children = new SegmentNode[0];
            }
            else
            {
                int numChildren = random.Next(2, maxChildren);
                
                node.Children = new List<SegmentNode>();
                for (int i = 0; i < numChildren; i++)
                {
                    node.Children.Add(GenerateTree(depth - 1, maxChildren, maxChildren, segmentID, name + "." + i, random));
                }
            }

            return node;
        }
Exemple #25
0
    //Method that asks the computerplayer for a move in 3x3 game
    public int AskForComputerMoveThree(char[] board, char turn)
    {
        Random rnd = new Random();
        int input;

        // Ask for players move
        Console.Write("Player " + turn + ". Make your move (0 - " + (BoardSize - 1) + "): ");
        input = rnd.Next(0, 8);//Random number for where the computer wan´t to place it´s marker

        // Make the move
        while (true)
        {
            bool validMove = MakeMove(board, turn, input);
            if (validMove == false)
            {
                Console.Write("Pick a new location (0 - " + (BoardSize - 1) + "): ");
                //New random number to pick a new location if space is occupied or invalid
                input = rnd.Next(0, 8);
            }
            else
                break;
        }

        return input;
    }
Exemple #26
0
        private XLoper MakeRandom(Random r)
        {
            XLoper x = new XLoper();
            x.Type = XLoper.xlTypeNil;
            int choice = r.Next(7);
            switch (choice)
            {
                case 0:
                    x.Type = XLoper.xlTypeStr;
                    x.Str = MakeRandomString(r.Next(1000));
                    break;
                case 1:
                    x.Type = XLoper.xlTypeNum;
                    x.Num = r.NextDouble() * 1000;
                    break;
                case 2:
                    x.Type = XLoper.xlTypeInt;
                    x.W = r.Next(1000);
                    break;
                case 3:
                    x.Type = XLoper.xlTypeBool;
                    x.Bool = r.Next(2) == 1;
                    break;
                case 4:
                    x.Type = XLoper.xlTypeStr;
                    x.Str = "";
                    break;
            }

            return x;
        }
    static void Main(string[] args)
    {
        Random rnd = new Random();
        OurStack<int> stack = new OurStack<int>();
        for (int i = 0; i < 10; i++)
        {
            stack.Push(rnd.Next(100));
        }
        int initialCount = stack.Count;
        Console.Write("origin numbers:");
        for (int i = 0; i < initialCount; i++)
        {
            Console.Write( stack.Pop() + " ");

        }

        Console.WriteLine();
        for (int i = 0; i < 10; i++)
        {
            stack.Push(rnd.Next(100));
        }

        Console.WriteLine("Show last(peek) : " + stack.Peek());
        Console.WriteLine("Show and remove last :" + stack.Pop() + "\nafter removing tha last one the last is :" + stack.Peek());
    }
    // Write a method that adds two positive integer numbers 
    // represented as arrays of digits (each array element arr[i]
    // contains a digit; the last digit is kept in arr[0]). 
    // Each of the numbers that will be added could have up to 10 000 digits.

    static void Main()
    {
        //variables
        int[] arrayOne = new int[6];
        int[] arrayTwo = new int[10];
        Random rand = new Random();

        //fill the arrays with Random numbers
        for (int i = 0; i < arrayOne.Length; i++)
        {
            arrayOne[i] = rand.Next(9);
        }
        for (int i = 0; i < arrayTwo.Length; i++)
        {
            arrayTwo[i] = rand.Next(9);
        }

        #region print arrays
        Console.Write("{ ".PadLeft(10));
        Console.Write(String.Join(",", arrayOne));
        Console.WriteLine(" }");
        Console.Write("{ ");
        Console.Write(String.Join(",", arrayTwo));
        Console.WriteLine(" }");
        Console.WriteLine();
        #endregion

        #region print result
        Console.Write("{ ");
        Console.Write(String.Join(",", AddArrays(arrayOne, arrayTwo)));   //call AddArrays method
        Console.WriteLine(" }");
        #endregion

    }
    static void Main()
    {
        Random rand = new Random();
        int random = rand.Next(1, 10);
        Console.WriteLine("Entering {0} parameters for the methods.", random);

        Console.Write("Parameters: ");
        int[] arr = new int[random];
        for (int i = 0; i < random; i++)
        {
            int elem = rand.Next(1000);
            Console.Write("{0} ", elem);
            arr[i] = elem;
        }
        Console.WriteLine();

        Console.Write("Minimum: {0}", Minimum(arr));
        Console.WriteLine();

        Console.Write("Maximum: {0}", Maximum(arr));
        Console.WriteLine();

        Console.Write("Average: {0:F2}", Average(arr));
        Console.WriteLine();

        Console.Write("Sum: {0}", Sum(arr));
        Console.WriteLine();

        Console.Write("Product: {0}", Product(arr));
        Console.WriteLine();
    }
    private static Int32 SlowRandom(Int32 min, Int32 max)
    {
        byte[] items = new byte[12];
        RNGCryptoServiceProvider.Create().GetBytes(items);

        Random rand1 = new Random((int)DateTime.Now.Ticks & 0x0000FFFF | BitConverter.ToInt32(items, 0));
        for (int i = 0; i < 100; i++)
        {
            rand1.Next();
        }

        Random rand2 = new Random((int)DateTime.Now.Ticks & 0x0000FFFF | rand1.Next() | BitConverter.ToInt32(items, 8));
        for (int i = 0; i < 100; i++)
        {
            rand1.Next();
            rand2.Next();
        }

        Random rand3 = new Random((int)DateTime.Now.Ticks & 0x0000FFFF | rand2.Next() | rand1.Next() | BitConverter.ToInt32(items, 4));
        for (int i = 0; i < 100; i++)
        {
            rand1.Next();
            rand2.Next();
            rand3.Next();
        }

        Random rnd = new Random((int)DateTime.Now.Ticks & 0x0000FFFF | rand3.Next() | rand2.Next() | rand1.Next());

        for (int i = 0; i < rand1.Next(100, 150); i++)
        {
            rnd.Next();
        }

        return rnd.Next(min, max);
    }
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <param name="min">Minimum value (inclusive)</param>
 /// <param name="max">Maximum value (inclusive)</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public decimal?Next(Random rand, decimal?min, decimal?max)
 {
     if (!(rand?.Next <bool>() ?? false))
     {
         return(null);
     }
     min ??= decimal.MinValue;
     max ??= decimal.MaxValue;
     return(rand.Next(min.Value, max.Value));
 }
Exemple #32
0
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <param name="min">Minimum value (inclusive)</param>
 /// <param name="max">Maximum value (inclusive)</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public DateTime?Next(Random rand, DateTime?min, DateTime?max)
 {
     if (!(rand?.Next <bool>() ?? false))
     {
         return(null);
     }
     min ??= DateTime.MinValue;
     max ??= DateTime.MaxValue;
     return(rand.Next(min.Value, max.Value));
 }
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <param name="min">Minimum value (inclusive)</param>
 /// <param name="max">Maximum value (inclusive)</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public TimeSpan?Next(Random rand, TimeSpan?min, TimeSpan?max)
 {
     if (!(rand?.Next <bool>() ?? false))
     {
         return(null);
     }
     min ??= TimeSpan.MinValue;
     max ??= TimeSpan.MaxValue;
     return(rand.Next(min.Value, max.Value));
 }
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <param name="min">Minimum value (inclusive)</param>
 /// <param name="max">Maximum value (inclusive)</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public long?Next(Random rand, long?min, long?max)
 {
     if (!(rand?.Next <bool>() ?? false))
     {
         return(null);
     }
     min ??= long.MinValue;
     max ??= long.MaxValue;
     return(rand.Next(min.Value, max.Value));
 }
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <param name="min">Minimum value (inclusive)</param>
 /// <param name="max">Maximum value (inclusive)</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public byte?Next(Random rand, byte?min, byte?max)
 {
     if (!(rand?.Next <bool>() ?? false))
     {
         return(null);
     }
     min ??= 0;
     max ??= 255;
     return(rand.Next(min.Value, max.Value));
 }
Exemple #36
0
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <param name="min">Minimum value (inclusive)</param>
 /// <param name="max">Maximum value (inclusive)</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public Guid?Next(Random rand, Guid?min, Guid?max)
 {
     if (!(rand?.Next <bool>() ?? false))
     {
         return(null);
     }
     min ??= Guid.Empty;
     max ??= Guid.Empty;
     return(rand.Next(min.Value, max.Value));
 }
Exemple #37
0
 /// <summary>
 /// Generates next object
 /// </summary>
 /// <param name="rand">Random number generator</param>
 /// <param name="previouslySeen">The previously seen.</param>
 /// <returns>The next object</returns>
 public override object?NextObj(Random rand, List <object> previouslySeen)
 {
     if (Min is null || Max is null)
     {
         return(null);
     }
     DateTime.TryParse((string)Min, out var TempMin);
     DateTime.TryParse((string)Max, out var TempMax);
     return(!(rand?.Next <bool>() ?? false) ? null : (object)rand.Next(TempMin, TempMax));
 }
Exemple #38
0
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <param name="min">Minimum value (inclusive)</param>
 /// <param name="max">Maximum value (inclusive)</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public ushort?Next(Random rand, ushort?min, ushort?max)
 {
     if (!(rand?.Next <bool>() ?? false))
     {
         return(null);
     }
     min ??= ushort.MinValue;
     max ??= ushort.MaxValue;
     return(rand.Next(min.Value, max.Value));
 }
Exemple #39
0
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <param name="min">Minimum value (inclusive)</param>
 /// <param name="max">Maximum value (inclusive)</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public char?Next(Random rand, char?min, char?max)
 {
     if (!(rand?.Next <bool>() ?? false))
     {
         return(null);
     }
     min ??= char.MinValue;
     max ??= char.MaxValue;
     return(rand.Next(min.Value, max.Value));
 }
Exemple #40
0
        public EmotivController()
        {
            // Give us a random name.
            Name = "Emotive Controller " + _rnd?.Next(0, 100).ToString() ?? "Ooops! Why'd you do that?";

            // Start listenting to our Emotiv object when it's emotion changes
            if (_emotiv != null)
            {
                _emotiv.EmotionChanged += OnEmotionChanged;
            }
        }
Exemple #41
0
        public static CharBoard ConstructBoard(IEnumerable <Word> wordSet, Random random, Word forceInclude = null)
        {
            var characters = wordSet
                             .OrderBy(w => w.Value == forceInclude?.Value ? 0 : w.Value.Length)
                             .Aggregate(Enumerable.Empty <char>(), AddWord)
                             .Take(32)
                             .OrderBy(_ => random?.Next() ?? 0)
                             .ToArray();

            var possibleWords = GetPossibleWords(characters, wordSet);

            return(new CharBoard(
                       characters.Select(c => new CharCell(c, Maybe.None <int>(), Maybe.None <Item>())).ToArray(),
                       possibleWords,
                       0
                       ));
        }
Exemple #42
0
 public int?internal_operation_seed()
 => _rng?.Next(0, int.MaxValue);
Exemple #43
0
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public ushort?Next(Random rand)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (ushort?)rand.Next <ushort>());
 }
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public long?Next(Random rand)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (long?)rand.Next <long>());
 }
Exemple #45
0
        private List<PlayerSetting> ParseReplayMetaToPlayerSettings(ReplaySlot[] slots)
        {
            var random = new Random();

            // TODO: set the correct factions & colors
            var pSettings = new List<PlayerSetting>();

            var availableColors = new HashSet<MultiplayerColor>(AssetStore.MultiplayerColors);

            foreach (var slot in slots)
            {
                var colorIndex = (int) slot.Color;
                if (colorIndex >= 0 && colorIndex < AssetStore.MultiplayerColors.Count)
                {
                    availableColors.Remove(AssetStore.MultiplayerColors.GetByIndex(colorIndex));
                }
            }

            foreach (var slot in slots)
            {
                var owner = PlayerOwner.Player;

                if (slot.SlotType == ReplaySlotType.Empty)
                {
                    continue;
                }

                var factionIndex = slot.Faction;
                if (factionIndex == -1) // random
                {
                    var maxFactionIndex = AssetStore.PlayerTemplates.Count;
                    var minFactionIndex = 2; // 0 and 1 are civilian and observer

                    var diff = maxFactionIndex - minFactionIndex;
                    factionIndex = minFactionIndex + (random.Next() % diff);
                }

                var faction = AssetStore.PlayerTemplates.GetByIndex(factionIndex).Side;

                ColorRgb color;

                var colorIndex = (int) slot.Color;
                if (colorIndex >= 0 && colorIndex < AssetStore.MultiplayerColors.Count)
                {
                    color = AssetStore.MultiplayerColors.GetByIndex(slot.Color).RgbColor;
                }
                else
                {
                    var multiplayerColor = availableColors.First();
                    color = multiplayerColor.RgbColor;
                    availableColors.Remove(multiplayerColor);
                }

                if (slot.SlotType == ReplaySlotType.Computer)
                {
                    switch (slot.ComputerDifficulty)
                    {
                        case ReplaySlotDifficulty.Easy:
                            owner = PlayerOwner.EasyAi;
                            break;

                        case ReplaySlotDifficulty.Medium:
                            owner = PlayerOwner.MediumAi;
                            break;

                        case ReplaySlotDifficulty.Hard:
                            owner = PlayerOwner.HardAi;
                            break;
                    }

                }
                pSettings.Add(new PlayerSetting(slot.StartPosition, faction, color, slot.Team, owner, slot.HumanName));
            }

            return pSettings;
        }
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public TimeSpan?Next(Random rand)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (TimeSpan?)rand.Next(TimeSpan.MinValue, TimeSpan.MaxValue));
 }
Exemple #47
0
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public float?Next(Random rand)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (float?)rand.Next <float>());
 }
        public Track?GetNext(Random?random)
        {
            Track?next = null;

            if (toPlayTracks.Count > 0)
            {
                var trackIndex      = random?.Next(toPlayTracks.Count) ?? 0;
                var playinglistItem = toPlayTracks[trackIndex];
                toPlayTracks.RemoveAt(trackIndex);
                if (playinglistItem is PlayinglistItemTrack playinglistItemTrack)
                {
                    next = playinglistItemTrack.Track;
                }
                else if (playinglistItem is PlayinglistItemPlaylistTrack playinglistItemPlaylistTrack)
                {
                    if (DC.Data.PlayinglistTracksByPlaylistTrackKey.TryGetValue(playinglistItemPlaylistTrack.PlaylistTrack.Key, out var playinglistTrack))
                    {
                        playinglistTrack.Release();
                        next = playinglistItemPlaylistTrack.PlaylistTrack.Track;
                    }
                    else
                    {
                        //PlayinglistTrack not found, Track might just have been removed from Playlist
                        //search for next existing playinglistItem
                        while (toPlayTracks.Count > 0)
                        {
                            if (trackIndex >= toPlayTracks.Count)
                            {
                                trackIndex = 0;
                            }
                            playinglistItem = toPlayTracks[trackIndex];
                            toPlayTracks.RemoveAt(trackIndex);
                            if (DC.Data.PlayinglistTracksByPlaylistTrackKey.TryGetValue(playinglistItemPlaylistTrack.PlaylistTrack.Key, out playinglistTrack))
                            {
                                playinglistTrack.Release();
                                return(playinglistItemPlaylistTrack.PlaylistTrack.Track);
                            }
                        }
                        System.Diagnostics.Debugger.Break();
                        return(null);
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }
            }

            if (toPlayTracks.Count == 0)
            {
                if (Playlist is null)
                {
                    if (allTracks.Count == 0)
                    {
                        System.Diagnostics.Debugger.Break();
                        return(null);
                    }
                    foreach (var copyTrack in allTracks)
                    {
                        toPlayTracks.Add(copyTrack);
                        if (copyTrack is PlayinglistItemPlaylistTrack playinglistItemPlaylistTrack)
                        {
                            System.Diagnostics.Debugger.Break();//We should never come here, because PlayinglistItemPlaylistTrack are not used when Playlist is null
                            //todo: change allTracks to List<PlayinglistItemTrack>
                            _ = new PlayinglistTrack(playinglistItemPlaylistTrack.PlaylistTrack.Key);
                        }
                    }
                }
                else
                {
                    fill(Playlist.PlaylistTracks);
                    if (toPlayTracks.Count == 0)
                    {
                        //it seems user has deleted all tracks from playlist
                        return(null);
                    }
                }
            }
            if (next is null)
            {
                //toPlayTracks was empty when GetNext() was called. Now toPlayTracks is supposed to be full, unless user deleted
                //all tracks which were in the playlist in the meantime
                System.Diagnostics.Debugger.Break();
                return(null);
            }
            return(next);
        }
Exemple #49
0
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public double?Next(Random rand)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (double?)rand.Next <double>());
 }
Exemple #50
0
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public Guid?Next(Random rand)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (Guid?)rand.Next <Guid>());
 }
Exemple #51
0
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public DateTime?Next(Random rand)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (DateTime?)rand.Next(DateTime.MinValue, DateTime.MaxValue));
 }
Exemple #52
0
 /// <summary>
 /// Generates next object
 /// </summary>
 /// <param name="rand">Random number generator</param>
 /// <param name="previouslySeen">The previously seen.</param>
 /// <returns>The next object</returns>
 public object?NextObj(Random rand, List <object> previouslySeen)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (object)rand.Next(DateTime.MinValue, DateTime.MaxValue));
 }
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public bool Next(Random rand)
 {
     return(rand?.Next(0, 2) == 1);
 }
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public byte?Next(Random rand)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (byte?)rand.Next <byte>());
 }
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public decimal?Next(Random rand)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (decimal?)rand.Next <decimal>());
 }
Exemple #56
0
 private void generateButton_Click(object sender, RoutedEventArgs e)
 {
     generatedNumber        = random?.Next(5, 100);
     generateTextBlock.Text = $"{generatedNumber}";
 }
Exemple #57
0
 /// <summary>
 /// Generates random election timeout.
 /// </summary>
 /// <returns>The randomized election timeout.</returns>
 public int RandomTimeout() => random?.Next(LowerValue, UpperValue + 1) ?? 0;
Exemple #58
0
 /// <summary>
 /// Generates a random value of the specified type
 /// </summary>
 /// <param name="rand">Random number generator that it can use</param>
 /// <returns>A randomly generated object of the specified type</returns>
 public char?Next(Random rand)
 {
     return(!(rand?.Next <bool>() ?? false) ? null : (char?)rand.Next <char>());
 }
Exemple #59
0
 public static byte NextByte(this Random random, byte minValue = 0, byte maxValue = 255) => (byte)random?.Next(minValue, maxValue);
Exemple #60
0
        static void Main(string[] args)
        {
            //teht1
            double i = 0;

            Console.WriteLine("luku    neliöjuuri");

            while (i <= 10)
            {
                Console.Write("\n{0}       {1}",i,Math.Sqrt(i));
                i++;
            }

            Console.WriteLine("\n");
            //teht2
            i = 1;
            int n = 1;

            while ( n < 10 && i < 10)
            {
                Console.WriteLine("{0} x {1} = {2}",n,i,n*i);
                i++;
                if(i == 10)
                {
                    n++;
                    i = 1;
                }
            }
            Console.WriteLine("\n");
            //teht3

            Random rnd = new Random();

            for (i = 1; i <= 4; i++)
            {
                Console.Write("\nRivi {0}: ", i);
                n = 1;
                while (n <= 5)
                {

                    if (n == 5)
                    {
                        Console.Write("{0}", rnd.Next(50));
                        break;
                    }
                    else
                    {
                        Console.Write("{0}, ", rnd.Next(50));
                        n++;
                    }
                }
            }

            Console.WriteLine("\n");
            //teht4

            int kruuna = 0, klaava = 0, input;

            Console.WriteLine("Syötä luku montako arpasuoritusta suoritetaan: ");
            input = int.Parse(Console.ReadLine());

            for (i = 0; i < input;i++)
            {
                int result = rnd.Next(2);
                if (result == 1)
                {
                    kruuna++;
                }
                else if (result == 0)
                {
                    klaava++;
                }
                else
                {
                    Console.Write("Virhe");
                    break;
                }
            }
            Console.WriteLine("Rahaa on heitetty {0} kertaa.",input);
            Console.WriteLine("Klaavoja tuli {0} ja kruunoja {1}", klaava, kruuna);

            Console.WriteLine("\n");
            //teht5

            for (i = 1; i <= 13; i++)
            {
                double result = rnd.NextDouble();
                if (result <= 0.4)
                {
                    Console.WriteLine("{0}. 1",i);
                }
                else if (0.4 < result && result < 0.6)
                {
                    Console.WriteLine("{0}. X",i);
                }
                else
                {
                    Console.WriteLine("{0}. 2",i);
                }
            }

            Console.WriteLine("\n");
            //teht5

            int kutonen = 0;

            for (i = 1; i <= 1000; i++)
            {
                int result = rnd.Next(6);
                result++;
                Console.Write("{0} ", result);
                if (result == 6)
                {
                    kutonen++;
                }
            }
            Console.WriteLine("Kuutosia tuli {0} kertaa", kutonen);


        }