Inheritance: global::java.lang.Object, global::java.io.Serializable
Example #1
0
        public static ArrayList generateDistinctSpeakers(int vectorSize, int vectorsCount, int speakersCount)
        {
            java.util.Random random    = new java.util.Random();
            ArrayList        arrayList = new ArrayList();

            float[] array = new float[vectorSize];
            for (int i = 0; i < speakersCount; i++)
            {
                for (int j = 0; j < vectorSize; j++)
                {
                    array[j] = (float)(i + 1) / 10f + (float)random.nextInt(5000) / 50000f;
                }
                array[0] = 3f + (float)(i + 1) / 10f;
                for (int j = 0; j < vectorsCount; j++)
                {
                    float[] array2 = new float[vectorSize];
                    for (int k = 0; k < vectorSize; k++)
                    {
                        array2[k] = array[k] + (float)random.nextInt(5000) / 50000f;
                    }
                    arrayList.add(array2);
                }
            }
            return(arrayList);
        }
Example #2
0
        public override bool generate(World world, Random random, int i, int j, int k)
        {
            for (int l = 0; l < 20; l++)
            {
                int i1 = (i + random.nextInt(4)) - random.nextInt(4);
                int j1 = j;
                int k1 = (k + random.nextInt(4)) - random.nextInt(4);
                if (!world.isAirBlock(i1, j1, k1) ||
                    world.getBlockMaterial(i1 - 1, j1 - 1, k1) != Material.water &&
                    world.getBlockMaterial(i1 + 1, j1 - 1, k1) != Material.water &&
                    world.getBlockMaterial(i1, j1 - 1, k1 - 1) != Material.water &&
                    world.getBlockMaterial(i1, j1 - 1, k1 + 1) != Material.water)
                {
                    continue;
                }
                int l1 = 2 + random.nextInt(random.nextInt(3) + 1);
                for (int i2 = 0; i2 < l1; i2++)
                {
                    if (Block.reed.canBlockStay(world, i1, j1 + i2, k1))
                    {
                        world.setBlock(i1, j1 + i2, k1, Block.reed.blockID);
                    }
                }
            }

            return true;
        }
Example #3
0
 public override void updateTick(World world, int i, int j, int k, Random random)
 {
     if (blockID == oreRedstoneGlowing.blockID)
     {
         world.setBlockWithNotify(i, j, k, oreRedstone.blockID);
     }
 }
Example #4
0
        public virtual void testRSACrypt1024_BiggerBlock()
        {
            System.Console.Out.WriteLine("RSACrypt1024Bigger");
            int            keySize = 1024;
            CryptobyClient client  = new CryptobyClient();
            CryptobyCore   core    = new CryptobyCore(client);

            java.util.Random rand = new java.util.Random();
            for (int i = 1; i < 50; i++)
            {
                byte[] expResult = new byte[i * 100];
                rand.nextBytes(expResult);
                KeyGenRSA generator = new KeyGenRSA(core);
                generator.initGenerator(keySize);
                byte[]   publicKey  = generator.getPublicKeyByte();
                byte[]   privateKey = generator.getPrivateKeyByte();
                CryptRSA rsa        = new CryptRSA();
                byte[]   encres     = rsa.encrypt(expResult, publicKey);
                byte[]   encres2    = rsa.encrypt(expResult, publicKey);;
                byte[]   result     = rsa.decrypt(encres, privateKey);
                byte[]   result2    = rsa.decrypt(encres2, privateKey);
                Assert.AreEqual(result, result2);
                Assert.AreEqual(expResult, result);
            }
        }
Example #5
0
 public override void updateTick(World world, int i, int j, int k, Random random)
 {
     if (world.singleplayerWorld)
     {
         return;
     }
     if (world.getBlockLightValue(i, j + 1, k) < 4 && world.getBlockMaterial(i, j + 1, k).getCanBlockGrass())
     {
         if (random.nextInt(4) != 0)
         {
             return;
         }
         world.setBlockWithNotify(i, j, k, dirt.blockID);
     }
     else if (world.getBlockLightValue(i, j + 1, k) >= 9)
     {
         int l = (i + random.nextInt(3)) - 1;
         int i1 = (j + random.nextInt(5)) - 3;
         int j1 = (k + random.nextInt(3)) - 1;
         if (world.getBlockId(l, i1, j1) == dirt.blockID && world.getBlockLightValue(l, i1 + 1, j1) >= 4 &&
             !world.getBlockMaterial(l, i1 + 1, j1).getCanBlockGrass())
         {
             world.setBlockWithNotify(l, i1, j1, grass.blockID);
         }
     }
 }
Example #6
0
 public override void updateTick(World world, int i, int j, int k, Random random)
 {
     if (world.getSavedLightValue(EnumSkyBlock.Block, i, j, k) > 11 - lightOpacity[blockID])
     {
         dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k));
         world.setBlockWithNotify(i, j, k, waterMoving.blockID);
     }
 }
Example #7
0
 public NoiseGeneratorOctaves(Random random, int i)
 {
     field_938_b = i;
     generatorCollection = new NoiseGeneratorPerlin[i];
     for (int j = 0; j < i; j++)
     {
         generatorCollection[j] = new NoiseGeneratorPerlin(random);
     }
 }
Example #8
0
 public override int idDropped(int i, Random random)
 {
     if (random.nextInt(10) == 0)
     {
         return Item.flint.shiftedIndex;
     }
     else
     {
         return blockID;
     }
 }
Example #9
0
 public override WorldGenerator getRandomWorldGenForTrees(Random random)
 {
     if (random.nextInt(3) == 0)
     {
         return new WorldGenBigTree();
     }
     else
     {
         return new WorldGenTrees();
     }
 }
Example #10
0
 public override int quantityDropped(Random random)
 {
     if (blockID == oreLapis.blockID)
     {
         return 4 + random.nextInt(5);
     }
     else
     {
         return 1;
     }
 }
Example #11
0
 public virtual void timeLinguist(int numRuns, int numFrames, int maxBeam)
 {
     java.util.Random  random = new java.util.Random((long)((ulong)1000));
     sphinx.util.Timer timer  = TimerPool.getTimer(this, "frameTimer");
     sphinx.util.Timer timer2 = TimerPool.getTimer(this, "totalTimer");
     [email protected](new StringBuilder().append("TestLinguist: runs ").append(numRuns).append(" frames ").append(numFrames).append(" beam ").append(maxBeam).toString());
     timer2.start();
     for (int i = 0; i < numRuns; i++)
     {
         int    num = 0;
         object obj = new ArrayList();
         ((ArrayList)obj).add(this.linguist.getSearchGraph().getInitialState());
         this.linguist.startRecognition();
         for (int j = 0; j < numFrames; j++)
         {
             object obj2 = obj;
             obj = new ArrayList(maxBeam * 10);
             timer.start();
             object obj3 = obj2;
             List   list;
             if (obj3 != null)
             {
                 if ((list = (obj3 as List)) == null)
                 {
                     throw new IncompatibleClassChangeError();
                 }
             }
             else
             {
                 list = null;
             }
             Iterator iterator = list.iterator();
             while (iterator.hasNext())
             {
                 SearchState searchState = (SearchState)iterator.next();
                 this.expandState(num, (ArrayList)obj, searchState);
             }
             timer.stop();
             Collections.shuffle((ArrayList)obj, random);
             if (((ArrayList)obj).size() > maxBeam)
             {
                 obj = ((ArrayList)obj).subList(0, maxBeam);
             }
         }
         this.linguist.stopRecognition();
     }
     timer2.stop();
     [email protected](new StringBuilder().append(" MaxSuccessors : ").append(this.maxSuccessors).toString());
     [email protected](new StringBuilder().append(" TotalStates   : ").append(this.totalStates).toString());
     [email protected](new StringBuilder().append(" TotalEmitting : ").append(this.totalEmittingStates).toString());
     [email protected](new StringBuilder().append("   NonEmitting : ").append(this.totalNonEmittingStates).toString());
     [email protected](new StringBuilder().append("  Final States : ").append(this.totalFinalStates).toString());
 }
Example #12
0
 public Explosion(World world, Entity entity, double d, double d1, double d2, float f)
 {
     isFlaming = false;
     ExplosionRNG = new Random();
     destroyedBlockPositions = new HashSet();
     worldObj = world;
     exploder = entity;
     explosionSize = f;
     explosionX = d;
     explosionY = d1;
     explosionZ = d2;
 }
Example #13
0
 public void func_21027_b(World world, int i, int j, int k, Random random)
 {
     world.setBlock(i, j, k, 0);
     object obj = new WorldGenTrees();
     if (random.nextInt(10) == 0)
     {
         obj = new WorldGenBigTree();
     }
     if (!((WorldGenerator) (obj)).generate(world, random, i, j, k))
     {
         world.setBlock(i, j, k, blockID);
     }
 }
        public Font getFont(int index)
        {
            java.util.Random r      = new java.util.Random();
            string           family = families[r.nextInt(families.Count)];
            bool             bold   = r.nextBoolean() && randomStyle;
            int size = minSize;

            if (maxSize - minSize > 0)
            {
                size += r.nextInt(maxSize - minSize);
            }
            return(new Font(family, bold ? Font.BOLD : Font.PLAIN, size));
        }
Example #15
0
 public static int func_21066_a(Random random)
 {
     int i = random.nextInt(100);
     if (i < 5)
     {
         return 15;
     }
     if (i < 10)
     {
         return 7;
     }
     return i >= 15 ? 0 : 8;
 }
Example #16
0
        public static void classifierOne(string classifierFileName, string predictionModel)
        {
            FileReader javaFileReader = new FileReader(classifierFileName);

            weka.core.Instances wekaInsts = new weka.core.Instances(javaFileReader);
            javaFileReader.close();

            wekaInsts.setClassIndex(wekaInsts.numAttributes() - 1);
            Classifier cl = new SMO();

            //Classifier cl = new NaiveBayes();
            java.util.Random random     = new java.util.Random(1);
            Evaluation       evaluation = new Evaluation(wekaInsts);

            evaluation.crossValidateModel(cl, wekaInsts, 10, random);

            foreach (object o in evaluation.getMetricsToDisplay().toArray())
            {
            }
            int           count = 0;
            StringBuilder sb    = new StringBuilder();

            foreach (object o in evaluation.predictions().toArray())
            {
                NominalPrediction prediction = o as NominalPrediction;
                if (prediction != null)
                {
                    double[] distribution = prediction.distribution();
                    double   predicted    = prediction.predicted();
                    double   actual       = prediction.actual();
                    string   revision     = prediction.getRevision();
                    double   weight       = prediction.weight();
                    double   margine      = prediction.margin();
                    //bool equals = prediction.@equals();

                    string distributions = String.Empty;
                    for (int i = 0; i < distribution.Length; i++)
                    {
                        //System.Console.WriteLine(distribution[i]);
                        distributions += distribution[i];
                    }
                    var predictionLine = String.Format("{0} - {1} - {2} - {3} - {4} - {5}\n", actual, predicted, revision, weight, margine, distributions);
                    sb.Append(predictionLine);
                    //System.Console.WriteLine(predicted);
                }
                count++;
            }
            File_Helper.WriteToFile(sb, predictionModel + "NbCl.txt");
            System.Console.WriteLine(count);
            System.Console.ReadKey();
        }
Example #17
0
        public Maze(long paramLong, int paramInt1, int paramInt2)
        {
            java.util.Random localRandom = new java.util.Random(paramLong);

            this.iteration    = 0;
            this.diagonal     = false;
            this.n_directions = 4;

            this.cde = new Key.Key_comparator();
            this.u   = new TreeSet(this.cde);

            this.size_x = paramInt1;
            this.size_y = paramInt2;

            this.cells = new Node[paramInt1, paramInt2];
            for (int ii = 0; ii < paramInt1; ii++)
            {
                for (int jj = 0; jj < paramInt2; jj++)
                {
                    this.cells[ii, jj] = new Node(ii, jj);
                }
            }

            int i = (int)(localRandom.nextDouble() * 2147483647.0D) % paramInt1;
            int j = (int)(localRandom.nextDouble() * 2147483647.0D) % paramInt2;

            this.original_start = (this.robot_cell = this.start = this.cells[i, j]);
            do
            {
                i         = (int)(localRandom.nextDouble() * 2147483647.0D) % paramInt1;
                j         = (int)(localRandom.nextDouble() * 2147483647.0D) % paramInt2;
                this.goal = this.cells[i, j];
            } while ((this.start.X == this.goal.X) && (this.start.Y == this.goal.Y));

            for (i = 0; i < paramInt1; i++)
            {
                for (j = 0; j < paramInt2; j++)
                {
                    this.cells[i, j].h         = (Math.Abs(i - this.goal.X) + Math.Abs(j - this.goal.Y));
                    this.cells[i, j].iteration = this.iteration;

                    if ((this.cells[i, j] == this.start) || (this.cells[i, j] == this.goal) ||
                        (localRandom.nextDouble() > 0.25D))
                    {
                        continue;
                    }
                    this.cells[i, j].real_type = 1;
                }
            }
        }
Example #18
0
        public override bool generate(World world, Random random, int i, int j, int k)
        {
            for (int l = 0; l < 64; l++)
            {
                int i1 = (i + random.nextInt(8)) - random.nextInt(8);
                int j1 = (j + random.nextInt(4)) - random.nextInt(4);
                int k1 = (k + random.nextInt(8)) - random.nextInt(8);
                if (world.isAirBlock(i1, j1, k1) && world.getBlockId(i1, j1 - 1, k1) == Block.bloodStone.blockID)
                {
                    world.setBlockWithNotify(i1, j1, k1, Block.fire.blockID);
                }
            }

            return true;
        }
Example #19
0
 public ChunkProviderHell(World world, long l)
 {
     field_4233_p = new double[256];
     field_4232_q = new double[256];
     field_4231_r = new double[256];
     field_4230_s = new MapGenCavesHell();
     field_4235_n = world;
     hellRNG = new Random(l);
     field_4240_i = new NoiseGeneratorOctaves(hellRNG, 16);
     field_4239_j = new NoiseGeneratorOctaves(hellRNG, 16);
     field_4238_k = new NoiseGeneratorOctaves(hellRNG, 8);
     field_4237_l = new NoiseGeneratorOctaves(hellRNG, 4);
     field_4236_m = new NoiseGeneratorOctaves(hellRNG, 4);
     field_4248_a = new NoiseGeneratorOctaves(hellRNG, 10);
     field_4247_b = new NoiseGeneratorOctaves(hellRNG, 16);
 }
Example #20
0
        public override bool generate(World world, Random random, int i, int j, int k)
        {
            for (int l = 0; l < 64; l++)
            {
                int i1 = (i + random.nextInt(8)) - random.nextInt(8);
                int j1 = (j + random.nextInt(4)) - random.nextInt(4);
                int k1 = (k + random.nextInt(8)) - random.nextInt(8);
                if (world.isAirBlock(i1, j1, k1) && world.getBlockId(i1, j1 - 1, k1) == Block.grass.blockID &&
                    Block.pumpkin.canPlaceBlockAt(world, i1, j1, k1))
                {
                    world.setBlockAndMetadata(i1, j1, k1, Block.pumpkin.blockID, random.nextInt(4));
                }
            }

            return true;
        }
Example #21
0
        public override bool generate(World world, Random random, int i, int j, int k)
        {
            for (int l = 0; l < 64; l++)
            {
                int i1 = (i + random.nextInt(8)) - random.nextInt(8);
                int j1 = (j + random.nextInt(4)) - random.nextInt(4);
                int k1 = (k + random.nextInt(8)) - random.nextInt(8);
                if (world.isAirBlock(i1, j1, k1) &&
                    (Block.blocksList[plantBlockId]).canBlockStay(world, i1, j1, k1))
                {
                    world.setBlock(i1, j1, k1, plantBlockId);
                }
            }

            return true;
        }
Example #22
0
 public override void updateTick(World world, int i, int j, int k, Random random)
 {
     base.updateTick(world, i, j, k, random);
     if (world.getBlockLightValue(i, j + 1, k) >= 9 && random.nextInt(5) == 0)
     {
         int l = world.getBlockMetadata(i, j, k);
         if (l < 15)
         {
             world.setBlockMetadataWithNotify(i, j, k, l + 1);
         }
         else
         {
             func_21027_b(world, i, j, k, random);
         }
     }
 }
Example #23
0
        public override bool generate(World world, Random random, int i, int j, int k)
        {
            if (world.getBlockMaterial(i, j, k) != Material.water)
            {
                return false;
            }
            float f = random.nextFloat()*3.141593F;
            double d = (i + 8) + (MathHelper.sin(f)*numberOfBlocks)/8F;
            double d1 = (i + 8) - (MathHelper.sin(f)*numberOfBlocks)/8F;
            double d2 = (k + 8) + (MathHelper.cos(f)*numberOfBlocks)/8F;
            double d3 = (k + 8) - (MathHelper.cos(f)*numberOfBlocks)/8F;
            double d4 = j + random.nextInt(3) + 2;
            double d5 = j + random.nextInt(3) + 2;
            for (int l = 0; l <= numberOfBlocks; l++)
            {
                double d6 = d + ((d1 - d)*l)/numberOfBlocks;
                double d7 = d4 + ((d5 - d4)*l)/numberOfBlocks;
                double d8 = d2 + ((d3 - d2)*l)/numberOfBlocks;
                double d9 = (random.nextDouble()*numberOfBlocks)/16D;
                double d10 = (MathHelper.sin((l*3.141593F)/numberOfBlocks) + 1.0F)*d9 + 1.0D;
                double d11 = (MathHelper.sin((l*3.141593F)/numberOfBlocks) + 1.0F)*d9 + 1.0D;
                for (var i1 = (int) (d6 - d10/2D); i1 <= (int) (d6 + d10/2D); i1++)
                {
                    for (var j1 = (int) (d7 - d11/2D); j1 <= (int) (d7 + d11/2D); j1++)
                    {
                        for (var k1 = (int) (d8 - d10/2D); k1 <= (int) (d8 + d10/2D); k1++)
                        {
                            double d12 = ((i1 + 0.5D) - d6)/(d10/2D);
                            double d13 = ((j1 + 0.5D) - d7)/(d11/2D);
                            double d14 = ((k1 + 0.5D) - d8)/(d10/2D);
                            if (d12*d12 + d13*d13 + d14*d14 >= 1.0D)
                            {
                                continue;
                            }
                            int l1 = world.getBlockId(i1, j1, k1);
                            if (l1 == Block.sand.blockID)
                            {
                                world.setBlock(i1, j1, k1, clayBlockId);
                            }
                        }
                    }
                }
            }

            return true;
        }
    protected void Button2_Click(object sender, EventArgs e)
    {
        weka.core.Instances data = new weka.core.Instances(new java.io.FileReader("d:\\train.arff"));
        data.setClassIndex(data.numAttributes() - 1);
        weka.classifiers.Classifier cls = new weka.classifiers.bayes.NaiveBayes();
        // weka.classifiers.functions.supportVector.SMOset();
        int runs  = 1;
        int folds = 10;

        //string sq = "delete from nbresults";
        //dbc.execfn(sq);
        // perform cross-validation
        for (int i = 0; i < runs; i++)
        {
            // randomize data
            int seed = i + 1;
            java.util.Random    rand     = new java.util.Random(seed);
            weka.core.Instances randData = new weka.core.Instances(data);
            randData.randomize(rand);
            if (randData.classAttribute().isNominal())
            {
                randData.stratify(folds);
            }
            // weka.classifiers.trees.j48 jj;
            weka.classifiers.Evaluation eval = new weka.classifiers.Evaluation(randData);
            for (int n = 0; n < folds; n++)
            {
                weka.core.Instances train = randData.trainCV(folds, n);
                weka.core.Instances test  = randData.testCV(folds, n);
                // build and evaluate classifier
                weka.classifiers.Classifier clsCopy = weka.classifiers.Classifier.makeCopy(cls);
                clsCopy.buildClassifier(train);

                eval.evaluateModel(clsCopy, test);
            }

            preci_value.Text  = eval.precision(0).ToString();
            recall_value.Text = eval.recall(0).ToString();
            acc_value.Text    = eval.fMeasure(0).ToString();

            string s = "NB";
            //    string str = "insert into evaluation values('" + instid.Text + "','" + courid.Text.ToString() + "','" + preci_value.Text.ToString() + "','" + recall_value.Text.ToString() + "','" + acc_value.Text.ToString() + "','" + s + "' )";
            //  db.execfn(str);
            //  MessageBox.Show("saved");
        }
    }
Example #25
0
 public override int idDropped(int i, Random random)
 {
     if (blockID == oreCoal.blockID)
     {
         return Item.coal.shiftedIndex;
     }
     if (blockID == oreDiamond.blockID)
     {
         return Item.diamond.shiftedIndex;
     }
     if (blockID == oreLapis.blockID)
     {
         return Item.dyePowder.shiftedIndex;
     }
     else
     {
         return blockID;
     }
 }
        public NoiseGeneratorPerlin(Random random)
        {
            permutations = new int[512];
            xCoord = random.nextDouble()*256D;
            yCoord = random.nextDouble()*256D;
            zCoord = random.nextDouble()*256D;
            for (int i = 0; i < 256; i++)
            {
                permutations[i] = i;
            }

            for (int j = 0; j < 256; j++)
            {
                int k = random.nextInt(256 - j) + j;
                int l = permutations[j];
                permutations[j] = permutations[k];
                permutations[k] = l;
                permutations[j + 256] = permutations[j];
            }
        }
        public NoiseGenerator2(Random random)
        {
            field_4316_e = new int[512];
            field_4313_a = random.nextDouble()*256D;
            field_4312_b = random.nextDouble()*256D;
            field_4318_c = random.nextDouble()*256D;
            for (int i = 0; i < 256; i++)
            {
                field_4316_e[i] = i;
            }

            for (int j = 0; j < 256; j++)
            {
                int k = random.nextInt(256 - j) + j;
                int l = field_4316_e[j];
                field_4316_e[j] = field_4316_e[k];
                field_4316_e[k] = l;
                field_4316_e[j + 256] = field_4316_e[j];
            }
        }
Example #28
0
 public ChunkProviderGenerate(World world, long l)
 {
     sandNoise = new double[256];
     gravelNoise = new double[256];
     stoneNoise = new double[256];
     field_695_u = new MapGenCaves();
     field_707_i = new int[32][];
     for (int i = 0; i < 32; i++)
     {
         field_707_i[i] = new int[32];
     }
     worldObj = world;
     rand = new Random(l);
     field_705_k = new NoiseGeneratorOctaves(rand, 16);
     field_704_l = new NoiseGeneratorOctaves(rand, 16);
     field_703_m = new NoiseGeneratorOctaves(rand, 8);
     field_702_n = new NoiseGeneratorOctaves(rand, 4);
     field_701_o = new NoiseGeneratorOctaves(rand, 4);
     field_715_a = new NoiseGeneratorOctaves(rand, 10);
     field_714_b = new NoiseGeneratorOctaves(rand, 16);
     mobSpawnerNoise = new NoiseGeneratorOctaves(rand, 8);
 }
Example #29
0
 public override void updateTick(World world, int i, int j, int k, Random random)
 {
     if (random.nextInt(5) == 0)
     {
         if (isWaterNearby(world, i, j, k))
         {
             world.setBlockMetadataWithNotify(i, j, k, 7);
         }
         else
         {
             int l = world.getBlockMetadata(i, j, k);
             if (l > 0)
             {
                 world.setBlockMetadataWithNotify(i, j, k, l - 1);
             }
             else if (!isCropsNearby(world, i, j, k))
             {
                 world.setBlockWithNotify(i, j, k, dirt.blockID);
             }
         }
     }
 }
Example #30
0
 public ChunkGenerator(WorldManager world, long seed)
 {
     SandNoise = new double[256];
     GravelNoise = new double[256];
     StoneNoise = new double[256];
     CaveGen = new MapGenCaves();
     field_707_i = new int[32][];
     for (int i = 0; i < 32; i++)
     {
         field_707_i[i] = new int[32];
     }
     World = world;
     Rand = new Random(seed);
     Noise1 = new NoiseGeneratorOctaves(Rand, 16);
     Noise2 = new NoiseGeneratorOctaves(Rand, 16);
     Noise3 = new NoiseGeneratorOctaves(Rand, 8);
     Noise4 = new NoiseGeneratorOctaves(Rand, 4);
     Noise5 = new NoiseGeneratorOctaves(Rand, 4);
     Noise6 = new NoiseGeneratorOctaves(Rand, 10);
     Noise7 = new NoiseGeneratorOctaves(Rand, 16);
     MobSpawnerNoise = new NoiseGeneratorOctaves(Rand, 8);
 }
Example #31
0
 public virtual void testRSACrypt1024_BiggerBlock()
 {
     System.Console.Out.WriteLine("RSACrypt1024Bigger");
     int keySize = 1024;
     CryptobyClient client = new CryptobyClient();
     CryptobyCore core = new CryptobyCore(client);
     java.util.Random rand = new java.util.Random();
     for(int i = 1;i<50;i++){
         byte[] expResult = new byte[i * 100];
         rand.nextBytes(expResult);
         KeyGenRSA generator = new KeyGenRSA(core);
         generator.initGenerator(keySize);
         byte[] publicKey = generator.getPublicKeyByte();
         byte[] privateKey = generator.getPrivateKeyByte();
         CryptRSA rsa = new CryptRSA();
         byte[] encres = rsa.encrypt (expResult, publicKey);
         byte[] encres2 = rsa.encrypt (expResult, publicKey);;
         byte[] result = rsa.decrypt(encres, privateKey);
         byte[] result2 = rsa.decrypt(encres2, privateKey);
         Assert.AreEqual(result, result2);
         Assert.AreEqual(expResult, result);
     }
 }
Example #32
0
        public override bool generate(World world, Random random, int i, int j, int k)
        {
            for (int l = 0; l < 10; l++)
            {
                int i1 = (i + random.nextInt(8)) - random.nextInt(8);
                int j1 = (j + random.nextInt(4)) - random.nextInt(4);
                int k1 = (k + random.nextInt(8)) - random.nextInt(8);
                if (!world.isAirBlock(i1, j1, k1))
                {
                    continue;
                }
                int l1 = 1 + random.nextInt(random.nextInt(3) + 1);
                for (int i2 = 0; i2 < l1; i2++)
                {
                    if (Block.cactus.canBlockStay(world, i1, j1 + i2, k1))
                    {
                        world.setBlock(i1, j1 + i2, k1, Block.cactus.blockID);
                    }
                }
            }

            return true;
        }
Example #33
0
 public override void updateTick(World world, int i, int j, int k, Random random)
 {
     if (world.isAirBlock(i, j + 1, k))
     {
         int l;
         for (l = 1; world.getBlockId(i, j - l, k) == blockID; l++)
         {
         }
         if (l < 3)
         {
             int i1 = world.getBlockMetadata(i, j, k);
             if (i1 == 15)
             {
                 world.setBlockWithNotify(i, j + 1, k, blockID);
                 world.setBlockMetadataWithNotify(i, j, k, 0);
             }
             else
             {
                 world.setBlockMetadataWithNotify(i, j, k, i1 + 1);
             }
         }
     }
 }
Example #34
0
        /* Public: */
        public AlgorithmsTest()
        {
            DateTime t0 = DateTime.Now;

            int MazeCount    = 5;
            int TotalSearchs = 0;
            int SuccessCount = 0;

            for (int c = 0; c < MazeCount; c++)
            {
                int OneSearch = 0;

                HashSet blocked_cells = new HashSet(), unblocked_cells = new HashSet();
                long    seed = DateTime.Now.Ticks;
                //seed = 27261468842294L;
                LightCell        maze_cell;
                java.util.Random random = new java.util.Random(seed);
                System.Console.WriteLine("Seed: " + seed);

                Maze maze = new Maze(seed, MAZE_W, MAZE_H, PROBABILITY_TO_BLOCK_A_CELL, MAZE_CELL_MAX_COST);
                //GAAStarLazy gaa_star_lazy = new GAAStarLazy(maze , true , false , tie_breaking_strategy ,
                //        ManhattanDistanceHeuristic.GetManhattanDistanceHeuristic() , Maze.N_DIRECTIONS_WITHOUT_DIAGONALS);

                for (maze_cell = maze.GetStart(); maze_cell != maze.GetGoal();)
                {
                    AStar a_star = new AStar(maze, true, false, tie_breaking_strategy,
                                             ManhattanDistanceHeuristic.GetManhattanDistanceHeuristic(), Maze.N_DIRECTIONS_WITHOUT_DIAGONALS);

                    a_star.Solve();
                    OneSearch++;

                    //System.Console.WriteLine("A*:\n" + maze);
                    //System.Console.WriteLine("A*:\n");

                    //maze.CleanPath();
                    //gaa_star_lazy.Solve();

                    //System.Console.WriteLine("GAA*:\n");
                    //System.Console.WriteLine("GAA*:\n" + maze);

                    if (!a_star.HasSolution())
                    {
                        System.Console.WriteLine("No solution.");
                        //System.err.println("Fail: Some algorithms found the solution.");
                        //System.err.println("A*: " + a_star.HasSolution());

                        //System.exit(1);
                        Application.Restart();
                    }
                    else
                    {
                        SuccessCount++;
                        //System.Console.WriteLine(OneSearch + " The solution has the following cost: " + a_star.GetPathCost());
                    }

                    for (int distance = 0; maze_cell != maze.GetGoal(); distance += 1, maze_cell = maze_cell.GetNextMazeCell())
                    {
                        if (distance >= DISTANCE_BEFORE_CHANGE || !a_star.HasSolution())
                        {
                            LightCell new_goal;

                            maze.CleanPath();
                            maze.SetStart(maze_cell);
                            //gaa_star_lazy.InformNewStart(maze_cell);
                            blocked_cells.clear();
                            unblocked_cells.clear();

                            /* Block some cells. */
                            for (int i = 0; i < N_CHANGED_CELLS; i++)
                            {
                                LightCell blocked_maze_cell;
                                int       x, y;
                                x = random.nextInt(maze.GetW());
                                y = random.nextInt(maze.GetH());
                                blocked_maze_cell = maze.GetMazeCell(x, y);
                                if (blocked_maze_cell != maze.GetStart() && blocked_maze_cell != maze.GetGoal() && !blocked_maze_cell.IsBlocked() &&
                                    !blocked_cells.contains(blocked_maze_cell))
                                {
                                    blocked_maze_cell.Block();
                                    blocked_cells.add(blocked_maze_cell);
                                }
                            }

                            /* Unblock or change the cost of some cells. */
                            for (int i = 0; i < N_CHANGED_CELLS; i++)
                            {
                                LightCell unblocked_maze_cell;
                                int       x, y;
                                x = random.nextInt(maze.GetW());
                                y = random.nextInt(maze.GetH());
                                unblocked_maze_cell = maze.GetMazeCell(x, y);
                                if (!blocked_cells.contains(unblocked_maze_cell) && !unblocked_cells.contains(unblocked_maze_cell))
                                {
                                    int new_cost = random.nextInt(MAZE_CELL_MAX_COST) + 1;
                                    if (unblocked_maze_cell.IsBlocked() || unblocked_maze_cell.GetCost() > new_cost)
                                    {
                                        unblocked_cells.add(unblocked_maze_cell);
                                    }
                                    unblocked_maze_cell.SetCost(new_cost);
                                }
                            }

                            /* Change the goal. */
                            do
                            {
                                int x, y;
                                x        = random.nextInt(maze.GetW());
                                y        = random.nextInt(maze.GetH());
                                new_goal = maze.GetMazeCell(x, y);
                            } while (blocked_cells.contains(new_goal) || unblocked_cells.contains(new_goal) ||
                                     new_goal == maze.GetGoal() || new_goal == maze.GetStart());

                            if (new_goal.IsBlocked())
                            {
                                unblocked_cells.add(new_goal);
                                maze.SetGoal(new_goal);
                            }
                            else
                            {
                                int old_cost = maze.GetGoal().GetCost();
                                maze.SetGoal(new_goal);
                                if (old_cost > maze.GetGoal().GetCost())
                                {
                                    unblocked_cells.add(maze.GetGoal());
                                }
                            }

                            //gaa_star_lazy.InformNewGoal(new_goal);

                            //if(unblocked_cells.size() > 0) gaa_star_lazy.InformUnblockedCells(unblocked_cells);
                            break;
                        }
                    }
                }
                TotalSearchs += OneSearch;
                System.Console.WriteLine(c +
                                         " Goal is : [" + maze.GetGoal().X + ", " + maze.GetGoal().Y +
                                         "] Current is : [" + maze_cell.X + ", " + maze_cell.Y + "]"
                                         );
            }//End of produce 100 maze
            TimeSpan diff = (DateTime.Now - t0);

            System.Console.WriteLine("Total RunTime  : " + diff.ToString());
            System.Console.WriteLine("RunTime per search : " + (diff.TotalMilliseconds * 1000 / TotalSearchs) + " micro second");
            System.Console.WriteLine("Average count of search is : " + (TotalSearchs / MazeCount));
        }
Example #35
0
    /*******************************/

    /// <summary>
    /// Creates a new positive random number
    /// </summary>
    /// <param name="random">The last random obtained</param>
    /// <returns>Returns a new positive random number</returns>
    public static long NextLong(Random random)
    {
        return(random.nextLong());
    }
Example #36
0
        public override bool generate(World world, Random random, int i, int j, int k)
        {
            byte byte0 = 3;
            int l = random.nextInt(2) + 2;
            int i1 = random.nextInt(2) + 2;
            int j1 = 0;
            for (int k1 = i - l - 1; k1 <= i + l + 1; k1++)
            {
                for (int j2 = j - 1; j2 <= j + byte0 + 1; j2++)
                {
                    for (int i3 = k - i1 - 1; i3 <= k + i1 + 1; i3++)
                    {
                        Material material = world.getBlockMaterial(k1, j2, i3);
                        if (j2 == j - 1 && !material.isSolid())
                        {
                            return false;
                        }
                        if (j2 == j + byte0 + 1 && !material.isSolid())
                        {
                            return false;
                        }
                        if ((k1 == i - l - 1 || k1 == i + l + 1 || i3 == k - i1 - 1 || i3 == k + i1 + 1) && j2 == j &&
                            world.isAirBlock(k1, j2, i3) && world.isAirBlock(k1, j2 + 1, i3))
                        {
                            j1++;
                        }
                    }
                }
            }

            if (j1 < 1 || j1 > 5)
            {
                return false;
            }
            for (int l1 = i - l - 1; l1 <= i + l + 1; l1++)
            {
                for (int k2 = j + byte0; k2 >= j - 1; k2--)
                {
                    for (int j3 = k - i1 - 1; j3 <= k + i1 + 1; j3++)
                    {
                        if (l1 == i - l - 1 || k2 == j - 1 || j3 == k - i1 - 1 || l1 == i + l + 1 || k2 == j + byte0 + 1 ||
                            j3 == k + i1 + 1)
                        {
                            if (k2 >= 0 && !world.getBlockMaterial(l1, k2 - 1, j3).isSolid())
                            {
                                world.setBlockWithNotify(l1, k2, j3, 0);
                                continue;
                            }
                            if (!world.getBlockMaterial(l1, k2, j3).isSolid())
                            {
                                continue;
                            }
                            if (k2 == j - 1 && random.nextInt(4) != 0)
                            {
                                world.setBlockWithNotify(l1, k2, j3, Block.cobblestoneMossy.blockID);
                            }
                            else
                            {
                                world.setBlockWithNotify(l1, k2, j3, Block.cobblestone.blockID);
                            }
                        }
                        else
                        {
                            world.setBlockWithNotify(l1, k2, j3, 0);
                        }
                    }
                }
            }

            for (int i2 = 0; i2 < 2; i2++)
            {
                for (int l2 = 0; l2 < 3; l2++)
                {
                    int k3 = (i + random.nextInt(l*2 + 1)) - l;
                    int l3 = j;
                    int i4 = (k + random.nextInt(i1*2 + 1)) - i1;
                    if (!world.isAirBlock(k3, l3, i4))
                    {
                        continue;
                    }
                    int j4 = 0;
                    if (world.getBlockMaterial(k3 - 1, l3, i4).isSolid())
                    {
                        j4++;
                    }
                    if (world.getBlockMaterial(k3 + 1, l3, i4).isSolid())
                    {
                        j4++;
                    }
                    if (world.getBlockMaterial(k3, l3, i4 - 1).isSolid())
                    {
                        j4++;
                    }
                    if (world.getBlockMaterial(k3, l3, i4 + 1).isSolid())
                    {
                        j4++;
                    }
                    if (j4 != 1)
                    {
                        continue;
                    }
                    world.setBlockWithNotify(k3, l3, i4, Block.crate.blockID);
                    var tileentitychest = (TileEntityChest) world.getBlockTileEntity(k3, l3, i4);
                    int k4 = 0;
                    do
                    {
                        if (k4 >= 8)
                        {
                            goto label0;
                        }
                        ItemStack itemstack = pickCheckLootItem(random);
                        if (itemstack != null)
                        {
                            tileentitychest.setInventorySlotContents(
                                random.nextInt(tileentitychest.getSizeInventory()), itemstack);
                        }
                        k4++;
                    } while (true);
                }

                label0:
                ;
            }

            world.setBlockWithNotify(i, j, k, Block.mobSpawner.blockID);
            var tileentitymobspawner = (TileEntityMobSpawner) world.getBlockTileEntity(i, j, k);
            tileentitymobspawner.setMobID(pickMobSpawner(random));
            return true;
        }
Example #37
0
 private ItemStack pickCheckLootItem(Random random)
 {
     int i = random.nextInt(11);
     if (i == 0)
     {
         return new ItemStack(Item.saddle);
     }
     if (i == 1)
     {
         return new ItemStack(Item.ingotIron, random.nextInt(4) + 1);
     }
     if (i == 2)
     {
         return new ItemStack(Item.bread);
     }
     if (i == 3)
     {
         return new ItemStack(Item.wheat, random.nextInt(4) + 1);
     }
     if (i == 4)
     {
         return new ItemStack(Item.gunpowder, random.nextInt(4) + 1);
     }
     if (i == 5)
     {
         return new ItemStack(Item.silk, random.nextInt(4) + 1);
     }
     if (i == 6)
     {
         return new ItemStack(Item.bucketEmpty);
     }
     if (i == 7 && random.nextInt(100) == 0)
     {
         return new ItemStack(Item.appleGold);
     }
     if (i == 8 && random.nextInt(2) == 0)
     {
         return new ItemStack(Item.redstone, random.nextInt(4) + 1);
     }
     if (i == 9 && random.nextInt(10) == 0)
     {
         return new ItemStack(Item.itemsList[Item.record13.shiftedIndex + random.nextInt(2)]);
     }
     else
     {
         return null;
     }
 }
Example #38
0
 private string pickMobSpawner(Random random)
 {
     int i = random.nextInt(4);
     if (i == 0)
     {
         return "Skeleton";
     }
     if (i == 1)
     {
         return "Zombie";
     }
     if (i == 2)
     {
         return "Zombie";
     }
     if (i == 3)
     {
         return "Spider";
     }
     else
     {
         return "";
     }
 }
Example #39
0
        public override bool generate(World world, Random random, int i, int j, int k)
        {
            int l = random.nextInt(5) + 7;
            int i1 = l - random.nextInt(2) - 3;
            int j1 = l - i1;
            int k1 = 1 + random.nextInt(j1 + 1);
            bool flag = true;
            if (j < 1 || j + l + 1 > 128)
            {
                return false;
            }
            for (int l1 = j; l1 <= j + 1 + l && flag; l1++)
            {
                int j2 = 1;
                if (l1 - j < i1)
                {
                    j2 = 0;
                }
                else
                {
                    j2 = k1;
                }
                for (int l2 = i - j2; l2 <= i + j2 && flag; l2++)
                {
                    for (int k3 = k - j2; k3 <= k + j2 && flag; k3++)
                    {
                        if (l1 >= 0 && l1 < 128)
                        {
                            int j4 = world.getBlockId(l2, l1, k3);
                            if (j4 != 0 && j4 != Block.leaves.blockID)
                            {
                                flag = false;
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                }
            }

            if (!flag)
            {
                return false;
            }
            int i2 = world.getBlockId(i, j - 1, k);
            if (i2 != Block.grass.blockID && i2 != Block.dirt.blockID || j >= 128 - l - 1)
            {
                return false;
            }
            world.setBlock(i, j - 1, k, Block.dirt.blockID);
            int k2 = 0;
            for (int i3 = j + l; i3 >= j + i1; i3--)
            {
                for (int l3 = i - k2; l3 <= i + k2; l3++)
                {
                    int k4 = l3 - i;
                    for (int l4 = k - k2; l4 <= k + k2; l4++)
                    {
                        int i5 = l4 - k;
                        if ((Math.abs(k4) != k2 || Math.abs(i5) != k2 || k2 <= 0) &&
                            !Block.opaqueCubeLookup[world.getBlockId(l3, i3, l4)])
                        {
                            world.setBlockAndMetadata(l3, i3, l4, Block.leaves.blockID, 1);
                        }
                    }
                }

                if (k2 >= 1 && i3 == j + i1 + 1)
                {
                    k2--;
                    continue;
                }
                if (k2 < k1)
                {
                    k2++;
                }
            }

            for (int j3 = 0; j3 < l - 1; j3++)
            {
                int i4 = world.getBlockId(i, j + j3, k);
                if (i4 == 0 || i4 == Block.leaves.blockID)
                {
                    world.setBlockAndMetadata(i, j + j3, k, Block.wood.blockID, 1);
                }
            }

            return true;
        }
        private void kMeansClustering(Loader loader, int num)
        {
            Pool      meansPool  = loader.getMeansPool();
            ArrayList arrayList  = new ArrayList(this.numberOfClusters);
            ArrayList arrayList2 = new ArrayList(this.numberOfClusters);
            int       num2       = meansPool.size();
            int       num3       = num;

            int[] array = new int[this.numberOfClusters];
            int   num4  = this.numberOfClusters;
            int   num5  = num2;

            int[] array2 = new int[2];
            int   num6   = num5;

            array2[1] = num6;
            num6      = num4;
            array2[0] = num6;
            float[][][] array3 = (float[][][])ByteCodeHelper.multianewarray(typeof(float[][][]).TypeHandle, array2);
            int         num7   = 0;

            java.util.Random random = new java.util.Random();
            for (int i = 0; i < this.numberOfClusters; i++)
            {
                int num8 = random.nextInt(num2);
                arrayList2.add(meansPool.get(num8));
                arrayList.add(meansPool.get(num8));
                array[i] = 0;
            }
            while (num7 == 0 && num3 > 0)
            {
                this.corespondingClass = new int[meansPool.size()];
                int num9  = this.numberOfClusters;
                int num10 = num2;
                array2    = new int[2];
                num6      = num10;
                array2[1] = num6;
                num6      = num9;
                array2[0] = num6;
                float[][][] array4 = (float[][][])ByteCodeHelper.multianewarray(typeof(float[][][]).TypeHandle, array2);
                for (int i = 0; i < this.numberOfClusters; i++)
                {
                    arrayList.set(i, arrayList2.get(i));
                    array[i] = 0;
                }
                for (int i = 0; i < meansPool.size(); i++)
                {
                    float[] array5 = (float[])meansPool.get(i);
                    double  num11  = (double)this.euclidianDistance((float[])arrayList.get(0), array5);
                    int     num8   = 0;
                    for (int j = 1; j < this.numberOfClusters; j++)
                    {
                        double num12 = (double)this.euclidianDistance((float[])arrayList.get(j), array5);
                        if (num12 < num11)
                        {
                            num11 = num12;
                            num8  = j;
                        }
                    }
                    array4[num8][array[num8]] = array5;
                    this.corespondingClass[i] = num8;
                    int[] array6 = array;
                    num6   = num8;
                    array2 = array6;
                    array2[num6]++;
                }
                for (int i = 0; i < this.numberOfClusters; i++)
                {
                    float[] array7 = new float[((float[])meansPool.get(0)).Length];
                    if (array[i] > 0)
                    {
                        for (int j = 0; j < array[i]; j++)
                        {
                            for (int k = 0; k < ((float[])meansPool.get(0)).Length; k++)
                            {
                                float[] array8 = array7;
                                num6 = k;
                                float[] array9 = array8;
                                array9[num6] += array4[i][j][k];
                            }
                        }
                        for (int j = 0; j < ((float[])meansPool.get(0)).Length; j++)
                        {
                            float[] array10 = array7;
                            num6 = j;
                            float[] array9 = array10;
                            array9[num6] /= (float)array[i];
                        }
                        arrayList2.set(i, array7);
                    }
                }
                num7 = 1;
                for (int i = 0; i < this.numberOfClusters; i++)
                {
                    num7 = ((num7 == 0 || !this.isEqual((float[])arrayList2.get(i), (float[])arrayList.get(i))) ? 0 : 1);
                }
                num3--;
            }
        }
Example #41
-1
        public static void Test_predictClass(string classifierFileName)
        {
            FileReader javaFileReader = new FileReader(classifierFileName);

            weka.core.Instances insts = new weka.core.Instances(javaFileReader);
            javaFileReader.close();

            insts.setClassIndex(insts.numAttributes() - 1);

            weka.classifiers.Classifier cl = new weka.classifiers.trees.J48();
            System.Console.WriteLine("Performing " + percentSplit + "% split evaluation.");



            #region Manual Cross Fold
            Instances foldsData = new Instances(insts);
            int       folds     = 10;
            for (int n = 0; n < folds; n++)
            {
                Instances trainFold = foldsData.trainCV(folds, n);
                Instances testFold  = foldsData.testCV(folds, n);
            }
            #endregion



            #region
            int trainSize             = insts.numInstances() * percentSplit / 100;
            int testSize              = insts.numInstances() - trainSize;
            weka.core.Instances train = new weka.core.Instances(insts, 0, trainSize);

            cl.buildClassifier(train);
            #endregion

            //Classifier cls = new J48();
            Evaluation       eval = new Evaluation(insts);
            java.util.Random rand = new java.util.Random(1);  // using seed = 1
            int fold = 10;
            eval.crossValidateModel(cl, insts, fold, rand);
            System.Console.WriteLine("toClassDetailsString" + eval.toClassDetailsString());
            System.Console.WriteLine("toMatrixString\n" + eval.toMatrixString());
            System.Console.WriteLine("toCumulativeMarginDistributionString\n" + eval.toCumulativeMarginDistributionString());
            //System.Console.WriteLine("predictions\n" + eval.predictions());
            System.Console.ReadKey();

            //var numnerOfInst = insts.numInstances();

            //for (int i = trainSize; i < numnerOfInst; i++)
            //{
            //    weka.core.Instance currentInst = insts.instance(i);

            //    double pred = cl.classifyInstance(currentInst);
            //    System.Console.WriteLine("class Index: " + insts.instance(i).classIndex());
            //    System.Console.WriteLine(", class value: " + insts.instance(i).classValue());
            //    System.Console.WriteLine(", ID: " + insts.instance(i).value(0));
            //    System.Console.WriteLine(", actual: " + insts.classAttribute().value((int)insts.instance(i).classValue()));
            //    System.Console.WriteLine(", predicted: " + insts.classAttribute().value((int)pred));

            //}
        }