示例#1
0
        public static String NewRandom(RandomType randomType, int length)
        {
            Random random = new Random((Int32)DateTime.Now.Ticks);
            String result = "";
            var keyLength = 0;
            switch (randomType)
            {
                case RandomType.Number:
                    keyLength = numberKey.Length;
                    for (int index = 0; index < length; index++)
                        result += numberKey[random.Next(0, keyLength)];
                    return result;

                case RandomType.String:
                    keyLength = stringKey.Length;
                    for (int index = 0; index < length; index++)
                        result += stringKey[random.Next(0, keyLength)];
                    return result;

                case RandomType.Default:
                default:
                    keyLength = randomKeys.Length;
                    for (int index = 0; index < length; index++)
                        result += randomKeys[random.Next(0, keyLength)];
                    return result;
            }
        }
 /// <summary>   
 /// Returns random string   
 /// </summary>   
 /// <param name="type">type Apha, Numeric or Aphnumeric</param>   
 /// <param name="length">string length</param>   
 /// <returns>string</returns>   
 public static string Gerar(RandomType type, int length)
 {
     switch (type)
     {
         case RandomType.Numeric:
             return ObterNumero(length);
         case RandomType.Alpha:
             return ObterAlfa(length);
         case RandomType.Alphanumeric:
             return ObterAlfaNumerico(length);
         default:
             return ObterAlfaNumerico(length);
     }
 }
示例#3
0
        private static int[] GetDeck(ref int[] deck, ref int prevDeckLen, int firstCard, int cardsToSort, int cardsToShuffle, WeaponRandomGenerator rng, RandomType type)
        {
            var count = cardsToSort - firstCard;

            if (prevDeckLen < count)
            {
                deck        = new int[count];
                prevDeckLen = count;
            }

            Random rnd;

            if (type == RandomType.Acquire)
            {
                rnd = rng.AcquireRandom;
                rng.AcquireCurrentCounter += count;
            }
            else
            {
                rnd = rng.ClientProjectileRandom;
                rng.ClientProjectileCurrentCounter += count;
            }

            for (int i = 0; i < count; i++)
            {
                var j = i < cardsToShuffle?rnd.Next(i + 1) : i;

                deck[i] = deck[j];
                deck[j] = firstCard + i;
            }
            return(deck);
        }
示例#4
0
    // OnGUI
    void OnGUI()
    {
        // SAMPLING SIZE
        switch (_randomType)
        {
        case RandomType.NUMBER:    max_samplig_size = 10000; break;

        case RandomType.VECTOR_2D: max_samplig_size = 5000; break;

        case RandomType.VECTOR_3D: max_samplig_size = 1000; break;

        case RandomType.COLOR:     max_samplig_size = 400;  break;

        case RandomType.DICE:      max_samplig_size = 5000;  break;

        default: max_samplig_size = 5000; break;
        }
        // ADJUST CURRENT SIZE
        if (samplig_size > max_samplig_size)
        {
            samplig_size = max_samplig_size;
        }

        // DRAWING AREA
        GUILayout.BeginArea(new Rect(_area_margin, _area_margin, _graph_area_width, _graph_area_height));
        GUILayout.Box("", GUILayout.Width(_graph_area_width), GUILayout.Height(_graph_area_height));
        if (randomList != null && randomList.Count > 0)
        {
            switch (_randomType)
            {
            case RandomType.NUMBER:
                switch (_randomNumberType)
                {
                case RandomNumberType.VALUE:
                    UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height);
                    break;

                case RandomNumberType.RANGE:
                    UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, _range_min, _range_max);
                    break;

                default:
                    UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, true);
                    break;
                }
                break;

            case RandomType.VECTOR_2D:
                UnityRandomEditorDraw.DrawV2Plot(randomList, _graph_area_width, _graph_area_height, _randomVector2DType);
                break;

            case RandomType.VECTOR_3D:
                UnityRandomEditorDraw.DrawV3Plot(randomList, _graph_area_width, _graph_area_height, _randomVector3DType, alpha, beta);
                break;

            case RandomType.COLOR:
                UnityRandomEditorDraw.DrawColorPlot(randomList, _graph_area_width, _graph_area_height);
                break;

            case RandomType.DICE:
                // generate a new ArrayList with the Sum, then send to DrawXYPlot
                ArrayList sums = RandomDiceSums();
                sums.Sort();
                UnityRandomEditorDraw.DrawXYPlot(sums, _graph_area_width, _graph_area_height, true);
                break;

            case RandomType.SHUFFLEBAG:
                UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, shufflebag[0], shufflebag[shufflebag.Length - 1]);
                break;

            case RandomType.WEIGHTEDBAG:
                UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, 1, 10);
                break;

            default:
                // defailt is no drawing
                break;
            }
        }
        GUILayout.EndArea();

        // SAMPLE RANDOM BUTTON
        GUILayout.BeginArea(new Rect(_area_margin, _area_margin + _area_margin + _graph_area_height, _graph_area_width, 60));
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Generate Random Numbers", GUILayout.Height(60)))
        {
            this.SampleRandom();
        }
        EditorGUILayout.EndHorizontal();
        GUILayout.EndArea();

        // CONTROL PANEL RIGHT BOX
        GUILayout.BeginArea(new Rect(_area_margin + _area_margin + _graph_area_width, _area_margin, _editor_area_width, _editor_area_height));

        // TITLE
        EditorGUILayout.BeginVertical("box");
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("CHOOSE TYPE OF RANDOM TYPE: ");
        _randomType = (RandomType)EditorGUILayout.EnumPopup(_randomType, GUILayout.Width(100));
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();

        switch (_randomType)
        {
        case RandomType.NUMBER: RandomNumbersGUI();
            break;

        case RandomType.VECTOR_2D: RandomVector2DGUI();
            break;

        case RandomType.VECTOR_3D: RandomVector3DGUI();
            break;

        case RandomType.COLOR: RandomColorGUI();
            break;

        case RandomType.DICE: RandomDiceGUI();
            break;

        case RandomType.SHUFFLEBAG: ShuffleBagGUI();
            break;

        case RandomType.WEIGHTEDBAG: ShuffleBagGUI();
            break;

        default:
            break;
        }

        EditorGUILayout.BeginVertical("box");
        samplig_size = EditorGUILayout.IntSlider("Sampling Size:", samplig_size, 1, max_samplig_size);
        EditorGUILayout.EndVertical();

        if (randomList != null && randomList.Count > 0)
        {
            EditorGUILayout.BeginVertical("box");
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("SAVE", GUILayout.Width(100)))
            {
                this.Save();
            }
            GUILayout.FlexibleSpace();
            filename = EditorGUILayout.TextField(filename);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
        }


        // 3D VIEWS BUTTONS
        if (randomList != null && randomList.Count > 0 && _randomType == RandomType.VECTOR_3D &&
            (_randomVector3DType == RandomVector3DType.INSPHERE ||
             _randomVector3DType == RandomVector3DType.ONSPHERE ||
             _randomVector3DType == RandomVector3DType.ONCAP ||
             _randomVector3DType == RandomVector3DType.ONRING))
        {
            EditorGUILayout.BeginVertical("box");
            String rotationLabel = rotation ? "STOP ROTATE VIEW" : "START ROTATE VIEW";
            if (GUILayout.Button(rotationLabel, GUILayout.Height(60)))
            {
                rotation = !rotation;
            }
            EditorGUILayout.EndVertical();
        }
        GUILayout.EndArea();

        // if GUI has changed empty the Array
        if (GUI.changed && randomList != null && randomList.Count != 0)
        {
            CleanList();
            this.Repaint();
        }

        // if Array is empty stop rotation and reset alpha/beta
        if (randomList == null || randomList.Count == 0)
        {
            rotation = false;
            alpha    = beta = 0;
        }
    }
示例#5
0
 public double GenerateDouble(RandomType type = RandomType.InSecure, int length = 100)
 {
     return(BitConverter.ToDouble(Generate(type, length), 0));
 }
示例#6
0
 public virtual void TestObjOfType(RandomType param)
 {
 }
示例#7
0
        private static bool FindRandomBlock(WeaponSystem system, GridAi ai, Target target, Vector3D weaponPos, TargetInfo info, ConcurrentCachingList <MyCubeBlock> subSystemList, Weapon w, WeaponRandomGenerator wRng, RandomType type, ref BoundingSphereD waterSphere, bool checkPower = true)
        {
            var totalBlocks = subSystemList.Count;

            var topEnt = info.Target.GetTopMostParent();

            var entSphere   = topEnt.PositionComp.WorldVolume;
            var distToEnt   = MyUtils.GetSmallestDistanceToSphere(ref weaponPos, ref entSphere);
            var turretCheck = w != null;
            var topBlocks   = system.Values.Targeting.TopBlocks;
            var lastBlocks  = topBlocks > 10 && distToEnt < 1000 ? topBlocks : 10;
            var isPriroity  = false;

            if (lastBlocks < 250)
            {
                TargetInfo priorityInfo;
                MyEntity   fTarget;
                if (ai.Construct.Data.Repo.FocusData.Target[0] > 0 && MyEntities.TryGetEntityById(ai.Construct.Data.Repo.FocusData.Target[0], out fTarget) && ai.Targets.TryGetValue(fTarget, out priorityInfo) && priorityInfo.Target?.GetTopMostParent() == topEnt)
                {
                    isPriroity = true;
                    lastBlocks = totalBlocks < 250 ? totalBlocks : 250;
                }
                else if (ai.Construct.Data.Repo.FocusData.Target[1] > 0 && MyEntities.TryGetEntityById(ai.Construct.Data.Repo.FocusData.Target[1], out fTarget) && ai.Targets.TryGetValue(fTarget, out priorityInfo) && priorityInfo.Target?.GetTopMostParent() == topEnt)
                {
                    isPriroity = true;
                    lastBlocks = totalBlocks < 250 ? totalBlocks : 250;
                }
            }

            if (totalBlocks < lastBlocks)
            {
                lastBlocks = totalBlocks;
            }
            var      deck          = GetDeck(ref target.BlockDeck, ref target.BlockPrevDeckLen, 0, totalBlocks, topBlocks, wRng, type);
            var      physics       = system.Session.Physics;
            var      iGrid         = topEnt as IMyCubeGrid;
            var      gridPhysics   = iGrid?.Physics;
            Vector3D targetLinVel  = gridPhysics?.LinearVelocity ?? Vector3D.Zero;
            Vector3D targetAccel   = (int)system.Values.HardPoint.AimLeadingPrediction > 1 ? info.Target.Physics?.LinearAcceleration ?? Vector3D.Zero : Vector3.Zero;
            var      foundBlock    = false;
            var      blocksChecked = 0;
            var      blocksSighted = 0;

            for (int i = 0; i < totalBlocks; i++)
            {
                if (turretCheck && (blocksChecked > lastBlocks || isPriroity && (blocksSighted > 100 || blocksChecked > 50 && system.Session.RandomRayCasts > 500 || blocksChecked > 25 && system.Session.RandomRayCasts > 1000)))
                {
                    break;
                }

                var card  = deck[i];
                var block = subSystemList[card];

                if (!(block is IMyTerminalBlock) || block.MarkedForClose || checkPower && !block.IsWorking)
                {
                    continue;
                }

                system.Session.BlockChecks++;

                var    blockPos = block.CubeGrid.GridIntegerToWorld(block.Position);
                double rayDist;
                if (turretCheck)
                {
                    double distSqr;
                    Vector3D.DistanceSquared(ref blockPos, ref weaponPos, out distSqr);
                    if (distSqr > w.MaxTargetDistanceSqr || distSqr < w.MinTargetDistanceSqr)
                    {
                        continue;
                    }

                    blocksChecked++;
                    ai.Session.CanShoot++;
                    Vector3D predictedPos;
                    if (!Weapon.CanShootTarget(w, ref blockPos, targetLinVel, targetAccel, out predictedPos))
                    {
                        continue;
                    }

                    if (system.Session.WaterApiLoaded && waterSphere.Radius > 2 && waterSphere.Contains(predictedPos) != ContainmentType.Disjoint)
                    {
                        continue;
                    }

                    blocksSighted++;

                    system.Session.RandomRayCasts++;
                    IHitInfo hitInfo;
                    physics.CastRay(weaponPos, blockPos, out hitInfo, 15);

                    if (hitInfo?.HitEntity == null || hitInfo.HitEntity is MyVoxelBase)
                    {
                        continue;
                    }

                    var hitGrid = hitInfo.HitEntity as MyCubeGrid;
                    if (hitGrid != null)
                    {
                        if (hitGrid.MarkedForClose || hitGrid != block.CubeGrid && hitGrid.IsSameConstructAs(ai.MyGrid))
                        {
                            continue;
                        }
                        bool enemy;

                        var bigOwners = hitGrid.BigOwners;
                        if (bigOwners.Count == 0)
                        {
                            enemy = true;
                        }
                        else
                        {
                            var relationship = target.FiringCube.GetUserRelationToOwner(hitGrid.BigOwners[0]);
                            enemy = relationship != MyRelationsBetweenPlayerAndBlock.Owner &&
                                    relationship != MyRelationsBetweenPlayerAndBlock.FactionShare;
                        }

                        if (!enemy)
                        {
                            continue;
                        }
                    }

                    Vector3D.Distance(ref weaponPos, ref blockPos, out rayDist);
                    var shortDist = rayDist * (1 - hitInfo.Fraction);
                    var origDist  = rayDist * hitInfo.Fraction;
                    var topEntId  = block.GetTopMostParent().EntityId;
                    target.Set(block, hitInfo.Position, shortDist, origDist, topEntId);
                    foundBlock = true;
                    break;
                }

                Vector3D.Distance(ref weaponPos, ref blockPos, out rayDist);
                target.Set(block, block.PositionComp.WorldAABB.Center, rayDist, rayDist, block.GetTopMostParent().EntityId);
                foundBlock = true;
                break;
            }
            return(foundBlock);
        }
示例#8
0
    void OnGUI()
    {
        GUILayout.BeginHorizontal();
        GUILayout.Label("RandomType");
        if (GUILayout.Button(_randomType.ToString()))
        {
            Clear();
            // タイプ変更
            RandomType next = RandomType.None;
            switch (_randomType)
            {
            case RandomType.XorShift128: next = RandomType.XorShift64; break;

            case RandomType.XorShift64: next = RandomType.XorShift32; break;

            case RandomType.XorShift32: next = RandomType.Mwc32; break;

            case RandomType.Mwc32: next = RandomType.Mwc64; break;

            case RandomType.Mwc64: next = RandomType.Standard; break;

            case RandomType.Standard: next = RandomType.BadLcg; break;

            case RandomType.BadLcg: next = RandomType.PopularLcg; break;

            case RandomType.PopularLcg: next = RandomType.MinStd; break;

            case RandomType.MinStd: next = RandomType.XorShift128; break;
            }
            SetRandomType(next);
            if (_testType == TestType.Gorilla)
            {
                StartCoroutine(CoGorillaTest());
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("TestType");
        if (GUILayout.Button(_testType.ToString()))
        {
            Clear();
            // タイプ変更
            switch (_testType)
            {
            case TestType.Fill: _testType = TestType.Gorilla; break;

            case TestType.Gorilla: _testType = TestType.Fill; break;
            }
            if (_testType == TestType.Gorilla)
            {
                StartCoroutine(CoGorillaTest());
            }
        }
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Benchmark"))
        {
            StartCoroutine(CoBenchmark());
        }
        if (_benchmarkResult != null)
        {
            GUILayout.Label(_benchmarkResult);
        }
    }
示例#9
0
        public static string GenerateRandom(int Length, RandomType rt)
        {
            int initsize = 0;
            int beginsize = 0;
            int endsize = 0;
            Boolean IsCross = false;
            #region 判断是哪种类型
            switch (rt)
            {
                case RandomType.All:
                    {
                        initsize = 62;
                        beginsize = 1;
                        endsize = 62;
                        //IsCross = false;
                        break;
                    }
                case RandomType.Lowercased:
                    {
                        initsize = 26;
                        beginsize = 11;
                        endsize = 36;
                        //IsCross = false;
                        break;
                    }
                case RandomType.Uppercased:
                    {
                        initsize = 26;
                        beginsize = 37;
                        endsize = 62;
                        // IsCross = false;
                        break;
                    }
                case RandomType.Number:
                    {
                        initsize = 10;
                        beginsize = 1;
                        endsize = 10;
                        //IsCross = false;
                        break;
                    }
                case RandomType.UppercasedAndLowercased:
                    {
                        initsize = 52;
                        beginsize = 11;
                        endsize = 62;
                        //IsCross = false;
                        break;
                    }
                case RandomType.NumberAndLowercased:
                    {
                        initsize = 36;
                        beginsize = 1;
                        endsize = 36;
                        //IsCross = false;
                        break;
                    }
                case RandomType.NumberAndUppercased:
                    {
                        IsCross = true;
                        break;
                    }
            }
            #endregion

            System.Text.StringBuilder newRandom = new System.Text.StringBuilder(initsize);
            Random rd = new Random();
            if (!IsCross)
            {
                for (int i = 0; i < Length; i++)
                {
                    newRandom.Append(constant[rd.Next(beginsize, endsize)]);
                }
            }
            else
            {
                for (int i = 0; i < Length; i++)
                {
                    newRandom.Append(constant[rd.Next(1, 10)]);
                    newRandom.Append(constant[rd.Next(37, 62)]);
                }
            }

            return newRandom.ToString();
        }
示例#10
0
 public static String NewRandom(RandomType randomType, char toplimit, char lowerlimit)
 {
     return NewRandom(default(RandomType), toplimit, lowerlimit, 1);
 }
示例#11
0
 public static String NewRandom(RandomType randomType)
 {
     return NewRandom(randomType, 1);
 }
示例#12
0
        /// <summary>
        /// 随机生成
        /// </summary>
        /// <param name="Length"></param>
        /// <param name="rt"></param>
        /// <returns></returns>
        public static string GenerateRandom(int Length, RandomType rt)
        {
            int     initsize  = 0;
            int     beginsize = 0;
            int     endsize   = 0;
            Boolean IsCross   = false;

            switch (rt)
            {
            case RandomType.All:
            {
                initsize  = constant.Length; //constant数组的最大个数
                beginsize = 1;               //constant数组的开始下标
                endsize   = constant.Length; //constant数组的结束下标
                //IsCross = false;
                break;
            }

            case RandomType.Lowercased:
            {
                initsize  = 24;    //少了2个小写L,0
                beginsize = 9;
                endsize   = 32;
                //IsCross = false;
                break;
            }

            case RandomType.Uppercased:
            {
                initsize  = 25;              //
                beginsize = 33;
                endsize   = constant.Length; //constant数组的结束下标
                // IsCross = false;
                break;
            }

            case RandomType.Number:
            {
                initsize  = 8;
                beginsize = 1;
                endsize   = 8;
                //IsCross = false;
                break;
            }

            case RandomType.UppercasedAndLowercased:
            {
                initsize  = constant.Length - 8;
                beginsize = 9;
                endsize   = constant.Length;   //constant数组的结束下标
                //IsCross = false;
                break;
            }

            case RandomType.NumberAndLowercased:
            {
                initsize  = 32;
                beginsize = 1;
                endsize   = 32;
                //IsCross = false;
                break;
            }

            case RandomType.NumberAndUppercased:
            {
                IsCross = true;
                break;
            }
            }



            System.Text.StringBuilder newRandom = new System.Text.StringBuilder(initsize);
            Random rd = new Random(unchecked (roCount * (int)DateTime.Now.Ticks));

            roCount++;

            if (!IsCross)
            {
                for (int i = 0; i < Length; i++)
                {
                    newRandom.Append(constant[rd.Next(beginsize, endsize)]);
                }
            }
            else
            {
                for (int i = 0; i < Length; i++)
                {
                    newRandom.Append(constant[rd.Next(1, 8)]);
                    newRandom.Append(constant[rd.Next(33, constant.Length)]);
                }
            }

            return(newRandom.ToString());
        }
示例#13
0
 public void createRandomVertexs(Vector2 center, int num, RandomType randomType, float size)
 {
     while (DS.VerticesNum < num)
     {
         Vector2 pos = Vector2.zero;
         if (randomType == RandomType.circle)
         {
             pos = center + size * UnityEngine.Random.insideUnitCircle;
         }
         else if (randomType == RandomType.rect)
         {
             pos = center + new Vector2(UnityEngine.Random.Range(-size, size), UnityEngine.Random.Range(-size, size));
         }
         //Debug.Log(pos);
         addVertex(pos);
     }
 }
示例#14
0
 /// <summary>
 /// 随机码生成
 /// </summary>
 /// <param name="Length">长度</param>
 /// <param name="type">类型</param>
 /// <returns></returns>
 public static string GenerateRandom(int Length, RandomType type)
 {
     char[] constant = null;
     switch (type)
     {
         case RandomType.Char:
             constant = new char[26] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
             break;
         case RandomType.Num:
             constant = new char[10] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
             break;
         case RandomType.CharAndNum:
             constant = new char[36] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
             break;
     }
     StringBuilder newRandom = new StringBuilder();
     Random rd = new Random();
     for (int i = 0; i < Length; i++)
     {
         newRandom.Append(constant[rd.Next(constant.Length)]);
     }
     return newRandom.ToString();
 }
示例#15
0
 public int GenerateInt(RandomType type = RandomType.InSecure, int length = 100)
 {
     return(BitConverter.ToInt32(Generate(type, length), 0));
 }
    // OnGUI
    void OnGUI()
    {
        // SAMPLING SIZE
        switch (_randomType) {
            case RandomType.NUMBER:    max_samplig_size  = 10000; break;
            case RandomType.VECTOR_2D: max_samplig_size  = 5000; break;
            case RandomType.VECTOR_3D: max_samplig_size  = 1000; break;
            case RandomType.COLOR:     max_samplig_size  = 400;  break;
            case RandomType.DICE:      max_samplig_size  = 5000;  break;
            default: max_samplig_size = 5000; break;
        }
        // ADJUST CURRENT SIZE
        if (samplig_size > max_samplig_size) samplig_size = max_samplig_size;

        // DRAWING AREA
        GUILayout.BeginArea(new Rect(_area_margin,_area_margin,_graph_area_width, _graph_area_height));
        GUILayout.Box("", GUILayout.Width(_graph_area_width), GUILayout.Height(_graph_area_height));
        if (randomList != null && randomList.Count > 0) {
            switch (_randomType) {
            case RandomType.NUMBER:
                switch (_randomNumberType) {
                case RandomNumberType.VALUE:
                    UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height);
                break;
                case RandomNumberType.RANGE:
                    UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, _range_min, _range_max);
                break;
                default:
                    UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, true);
                break;
                }
            break;
            case RandomType.VECTOR_2D:
            UnityRandomEditorDraw.DrawV2Plot(randomList, _graph_area_width, _graph_area_height, _randomVector2DType);
            break;
            case RandomType.VECTOR_3D:
            UnityRandomEditorDraw.DrawV3Plot(randomList, _graph_area_width, _graph_area_height, _randomVector3DType, alpha, beta);
            break;
            case RandomType.COLOR:
            UnityRandomEditorDraw.DrawColorPlot(randomList, _graph_area_width, _graph_area_height);
            break;
            case RandomType.DICE:
            // generate a new ArrayList with the Sum, then send to DrawXYPlot
            ArrayList sums = RandomDiceSums();
            sums.Sort();
            UnityRandomEditorDraw.DrawXYPlot(sums, _graph_area_width, _graph_area_height, true);
            break;
            case RandomType.SHUFFLEBAG:
            UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, shufflebag[0], shufflebag[shufflebag.Length - 1]);
            break;
            case RandomType.WEIGHTEDBAG:
            UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, 1, 10);
            break;
            default:
            // defailt is no drawing
            break;
            }
        }
        GUILayout.EndArea();

        // SAMPLE RANDOM BUTTON
        GUILayout.BeginArea(new Rect(_area_margin, _area_margin + _area_margin + _graph_area_height, _graph_area_width, 60));
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Generate Random Numbers",GUILayout.Height(60))) {
            this.SampleRandom();
        }
        EditorGUILayout.EndHorizontal();
        GUILayout.EndArea();

        // CONTROL PANEL RIGHT BOX
        GUILayout.BeginArea(new Rect(_area_margin + _area_margin +_graph_area_width, _area_margin, _editor_area_width, _editor_area_height));

        // TITLE
        EditorGUILayout.BeginVertical("box");
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("CHOOSE TYPE OF RANDOM TYPE: ");
        _randomType = (RandomType) EditorGUILayout.EnumPopup(_randomType, GUILayout.Width(100));
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();

        switch (_randomType) {

        case RandomType.NUMBER:	RandomNumbersGUI();
        break;

        case RandomType.VECTOR_2D: RandomVector2DGUI();
        break;

        case RandomType.VECTOR_3D: RandomVector3DGUI();
        break;

        case RandomType.COLOR: RandomColorGUI();
        break;

        case RandomType.DICE: RandomDiceGUI();
        break;

        case RandomType.SHUFFLEBAG: ShuffleBagGUI();
        break;

        case RandomType.WEIGHTEDBAG: ShuffleBagGUI();
        break;

        default:
        break;
        }

        EditorGUILayout.BeginVertical("box");
        samplig_size = EditorGUILayout.IntSlider ("Sampling Size:", samplig_size, 1, max_samplig_size);
        EditorGUILayout.EndVertical();

        if (randomList != null && randomList.Count > 0) {
            EditorGUILayout.BeginVertical("box");
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("SAVE",GUILayout.Width(100))) this.Save();
            GUILayout.FlexibleSpace();
            filename = EditorGUILayout.TextField(filename);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
        }

        // 3D VIEWS BUTTONS
        if (randomList != null && randomList.Count > 0 && _randomType == RandomType.VECTOR_3D &&
            (_randomVector3DType == RandomVector3DType.INSPHERE ||
             _randomVector3DType == RandomVector3DType.ONSPHERE ||
             _randomVector3DType == RandomVector3DType.ONCAP ||
            _randomVector3DType == RandomVector3DType.ONRING )) {
            EditorGUILayout.BeginVertical("box");
            String rotationLabel = rotation ? "STOP ROTATE VIEW" : "START ROTATE VIEW";
            if (GUILayout.Button(rotationLabel,GUILayout.Height(60))) {
                rotation = !rotation;
            }
            EditorGUILayout.EndVertical();
        }
        GUILayout.EndArea();

        // if GUI has changed empty the Array
        if (GUI.changed && randomList != null && randomList.Count != 0) {
            CleanList();
            this.Repaint();
        }

        // if Array is empty stop rotation and reset alpha/beta
        if (randomList == null || randomList.Count == 0) {
            rotation = false;
            alpha = beta = 0;
        }
    }
示例#17
0
        public static String NewRandom(RandomType randomType, char toplimit, char lowerlimit, int length)
        {
            Random random = new Random((Int32)DateTime.Now.Ticks);
            String result = "";
            switch (randomType)
            {
                case RandomType.Number:
                    if (numberKey.Contains(toplimit) && numberKey.Contains(lowerlimit))
                    {
                        var startIndex = numberKey.IndexOf(toplimit);
                        var endIndex = numberKey.IndexOf(lowerlimit);
                        if (startIndex > endIndex || endIndex > numberKey.Length)
                            throw new IndexOutOfRangeException("传入字符不在要求范围内");

                        for (int index = 0; index < length; index++)
                            result += numberKey[random.Next(startIndex, endIndex)];
                        return result;
                    }
                    else
                        throw new IndexOutOfRangeException("传入字符不在要求范围内");

                case RandomType.String:
                    if (stringKey.Contains(toplimit) && stringKey.Contains(lowerlimit))
                    {
                        var startIndex = stringKey.IndexOf(toplimit);
                        var endIndex = stringKey.IndexOf(lowerlimit);
                        if (startIndex > endIndex || endIndex > stringKey.Length)
                            throw new IndexOutOfRangeException("传入字符不在要求范围内");

                        for (int index = 0; index < length; index++)
                            result += stringKey[random.Next(startIndex, endIndex)];
                        return result;
                    }
                    else
                        throw new IndexOutOfRangeException("传入字符不在要求范围内");

                case RandomType.Default:
                default:
                    if (randomKeys.Contains(toplimit) && randomKeys.Contains(lowerlimit))
                    {
                        var startIndex = randomKeys.IndexOf(toplimit);
                        var endIndex = randomKeys.IndexOf(lowerlimit);
                        if (startIndex > endIndex || endIndex > randomKeys.Length)
                            throw new IndexOutOfRangeException("传入字符不在要求范围内");

                        for (int index = 0; index < length; index++)
                            result += randomKeys[random.Next(startIndex, endIndex)];
                        return result;
                    }
                    else
                        throw new IndexOutOfRangeException("传入字符不在要求范围内");
            }
        }
示例#18
0
 /// <summary>
 /// 生成随机号
 /// </summary>
 /// <param name="length">长度</param>
 /// <param name="randomType">类型</param>
 /// <returns></returns>
 public static string GenRandomNumber(int length, RandomType randomType)
 {
     string[] source = null;
     string code = "";
     switch (randomType)
     {
         case RandomType.Number:
             source = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
             break;
         case RandomType.Letter:
             source = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
             break;
         case RandomType.NumberAndLetter:
             source = new string[] { "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
             break;
         default:
             source = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
             break;
     }
     Random rd = new Random();
     for (int i = 0; i < length; i++)
     {
         code += source[rd.Next(0, source.Length)];
     }
     return code;
 }
示例#19
0
        /// <summary>
        /// Used to generate random string of specified length and type
        /// </summary>
        /// <param name="length">An integer specifying the length on the random string</param>
        /// <param name="safe">A RandomType enum specifying random string type</param>
        /// <returns>random string</returns>
        private static string GetRandomString(int length, RandomType rnd)
        {
            // Negative numbers indicate a random string length of 10-20 is desired.
            if (length < 0)
                length = 10 + s_random.Next(11);

            char[] chars = new char[length];
            for (int i = 0; i < length; i++)
            {
                switch (rnd)
                {
                    case RandomType.String:
                        switch (s_random.Next(3))
                        {
                            case 0:
                                // Get a random char between ascii 65 and 90 (upper case alphabets).
                                chars[i] = (char)(65 + s_random.Next(26));
                                break;
                            case 1:
                                // Get a random char between ascii 97 and 122 (lower case alphabets).
                                chars[i] = (char)(97 + s_random.Next(26));
                                break;
                            case 2:
                                // Get a random number 0 - 9
                                chars[i] = (char)('0' + s_random.Next(10));
                                break;
                        }
                        break;
                    case RandomType.File:
                        // 10% use SafeFileChars
                        if (s_random.Next(10) == 0)
                        {
                            // Get a random char from SafeFileChars
                            chars[i] = SafeFileChars[s_random.Next(SafeFileChars.Length)];
                        }
                        else
                        {
                            goto case 0;  // value - RandomType.String
                        }
                        break;
                    case RandomType.None:
                        // Get a random char from ascii 32 - 126
                        chars[i] = (char)(32 + s_random.Next(95));
                        break;
                    case RandomType.HighByte:
                        // Get a random char from ascii 128 - 65535
                        chars[i] = (char)(128 + s_random.Next(65407));                 
                        break;
                }
            }
            return new string(chars);
        }
示例#20
0
 public NNEvaluatorRandom(RandomType randomType, bool isWDL)
 {
     this.isWDL = isWDL;
     Type       = randomType;
 }
示例#21
0
        private static bool AcquireBlock(WeaponSystem system, GridAi ai, Target target, TargetInfo info, Vector3D weaponPos, WeaponRandomGenerator wRng, RandomType type, ref BoundingSphereD waterSphere, Weapon w = null, bool checkPower = true)
        {
            if (system.TargetSubSystems)
            {
                var subSystems     = system.Values.Targeting.SubSystems;
                var targetLinVel   = info.Target.Physics?.LinearVelocity ?? Vector3D.Zero;
                var targetAccel    = (int)system.Values.HardPoint.AimLeadingPrediction > 1 ? info.Target.Physics?.LinearAcceleration ?? Vector3D.Zero : Vector3.Zero;
                var focusSubSystem = w != null && w.Comp.Data.Repo.Base.Set.Overrides.FocusSubSystem;

                foreach (var blockType in subSystems)
                {
                    var bt = focusSubSystem ? w.Comp.Data.Repo.Base.Set.Overrides.SubSystem : blockType;

                    ConcurrentDictionary <BlockTypes, ConcurrentCachingList <MyCubeBlock> > blockTypeMap;
                    system.Session.GridToBlockTypeMap.TryGetValue((MyCubeGrid)info.Target, out blockTypeMap);
                    if (bt != Any && blockTypeMap != null && blockTypeMap[bt].Count > 0)
                    {
                        var subSystemList = blockTypeMap[bt];
                        if (system.ClosestFirst)
                        {
                            if (target.Top5.Count > 0 && (bt != target.LastBlockType || target.Top5[0].CubeGrid != subSystemList[0].CubeGrid))
                            {
                                target.Top5.Clear();
                            }

                            target.LastBlockType = bt;
                            if (GetClosestHitableBlockOfType(subSystemList, ai, target, weaponPos, targetLinVel, targetAccel, ref waterSphere, w, checkPower))
                            {
                                return(true);
                            }
                        }
                        else if (FindRandomBlock(system, ai, target, weaponPos, info, subSystemList, w, wRng, type, ref waterSphere, checkPower))
                        {
                            return(true);
                        }
                    }

                    if (focusSubSystem)
                    {
                        break;
                    }
                }

                if (system.OnlySubSystems || focusSubSystem && w.Comp.Data.Repo.Base.Set.Overrides.SubSystem != Any)
                {
                    return(false);
                }
            }
            FatMap fatMap;

            return(system.Session.GridToFatMap.TryGetValue((MyCubeGrid)info.Target, out fatMap) && fatMap.MyCubeBocks != null && FindRandomBlock(system, ai, target, weaponPos, info, fatMap.MyCubeBocks, w, wRng, type, ref waterSphere, checkPower));
        }
示例#22
0
 private double[] GenerateTrapezoidal(double a, double b, double c, double d, int n, RandomType type)
 {
     double[] first  = new double[n];
     double[] second = new double[n];
     double[] result = new double[n];
     for (int i = 0; i < n; i++)
     {
         first[i] = random.NextDouble(type) * (b - a) + a;
     }
     for (int i = 0; i < n; i++)
     {
         second[i] = random.NextDouble(type) * (d - c) + c;
     }
     for (int i = 0; i < n; i++)
     {
         result[i] = first[i] + second[i];
     }
     return(result);
 }
示例#23
0
        public void Can_call_method_with_typed_object_parameter()
        {
            var o = new RandomType();

            Test(x => x.TestObjOfType(It.Is <RandomType>(v => v.Equals(o))), o);
        }
示例#24
0
        public double[,] CreateHistogram(double a, double b, int n, int intervals, Distribution distribution, double c, double d, RandomType type)
        {
            double[] values = new double[1];
            switch (distribution)
            {
            case Distribution.Even:
                values = GenerateEven(a, b, n, type);
                break;

            case Distribution.Triangular:
                //values = ConvertToTriangular(values, param);
                values = GenerateTriangular(a, b, c, n, type);
                //n = n / 2;
                break;

            case Distribution.Exponential:
                values = GenerateExponential(a, b, c, n, type);
                break;

            case Distribution.Trapezoidal:
                values = GenerateTrapezoidal(a, b, c, d, n, type);
                break;

            case Distribution.Normal:
                values = GenerateNormal(c, d, n, 12, type);
                break;
            }
            double h = Math.Abs((values.Max() - values.Min()) / intervals);

            double[,] result = new double[intervals, 2];
            double min = values.Min();

            for (int i = 0; i < intervals; i++)
            {
                result[i, 0] = min + (h / 2);
                result[i, 1] = 0;
                min          = min + h;
            }
            min = values.Min();
            Array.Sort(values);
            int f = 0;
            int j = 0;

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i] < min + h)
                {
                    f++;
                }
                else
                {
                    result[j, 1] = (double)f / (double)n;
                    //result[j, 2] = f;
                    f = 0;
                    j++;
                    min = min + h;
                }
            }
            if (j < intervals)
            {
                result[j, 0] = min + (h / 2);
                result[j, 1] = (double)f / (double)n;
                j++;
            }
            return(result);
        }
示例#25
0
        public static string GenerateRandom(int Length, RandomType rt)
        {
            int     initsize  = 0;
            int     beginsize = 0;
            int     endsize   = 0;
            Boolean IsCross   = false;

            #region 判断是哪种类型
            switch (rt)
            {
            case RandomType.All:
            {
                initsize  = 62;
                beginsize = 1;
                endsize   = 62;
                //IsCross = false;
                break;
            }

            case RandomType.Lowercased:
            {
                initsize  = 26;
                beginsize = 11;
                endsize   = 36;
                //IsCross = false;
                break;
            }

            case RandomType.Uppercased:
            {
                initsize  = 26;
                beginsize = 37;
                endsize   = 62;
                // IsCross = false;
                break;
            }

            case RandomType.Number:
            {
                initsize  = 10;
                beginsize = 1;
                endsize   = 10;
                //IsCross = false;
                break;
            }

            case RandomType.UppercasedAndLowercased:
            {
                initsize  = 52;
                beginsize = 11;
                endsize   = 62;
                //IsCross = false;
                break;
            }

            case RandomType.NumberAndLowercased:
            {
                initsize  = 36;
                beginsize = 1;
                endsize   = 36;
                //IsCross = false;
                break;
            }

            case RandomType.NumberAndUppercased:
            {
                IsCross = true;
                break;
            }
            }
            #endregion

            System.Text.StringBuilder newRandom = new System.Text.StringBuilder(initsize);
            Random rd = new Random();
            if (!IsCross)
            {
                for (int i = 0; i < Length; i++)
                {
                    newRandom.Append(constant[rd.Next(beginsize, endsize)]);
                }
            }
            else
            {
                for (int i = 0; i < Length; i++)
                {
                    newRandom.Append(constant[rd.Next(1, 10)]);
                    newRandom.Append(constant[rd.Next(37, 62)]);
                }
            }

            return(newRandom.ToString());
        }
示例#26
0
 public string GenerateString(RandomType type = RandomType.InSecure, int length = 100)
 {
     return(Convert.ToBase64String(Generate(type, length)));
 }