Esempio n. 1
0
        public void GenerateSketches(int count)
        {
            _sketches = new CoinSketch[count];

            var index  = 0;
            var coinId = 0u;

            while (index < _sketches.Length)
            {
                // Production event
                var s0 = new CoinSketch((float)_rand.NextDouble(), coinId);
                _sketches[index++] = s0;

                if (index >= _sketches.Length)
                {
                    break;
                }

                // Read event
                var delta1 = 1f;
                for (var i = 0; i < 10; i++)
                {
                    delta1 *= (float)_rand.NextDouble();
                }

                var s1 = new CoinSketch(s0.Time + delta1, coinId + 1);

                if (s1.Time >= 1)
                {
                    continue;
                }

                _sketches[index++] = s1;

                if (index >= _sketches.Length)
                {
                    break;
                }

                // Consumption event
                var delta2 = 100f / count;

                var s2 = new CoinSketch(s1.Time + delta2, coinId + 2);

                if (s2.Time >= 1)
                {
                    continue;
                }

                _sketches[index++] = s2;

                coinId += 4;
            }

            Array.Sort(_sketches);
        }
Esempio n. 2
0
        private static unsafe Outpoint GetOutpoint(CoinSketch sketch, int seed)
        {
            var outpoint = new Outpoint();

            for (var i = 0; i < 4; i++)
            {
                outpoint.TxId[i] = (byte)(sketch.CoinId >> (i * 8 + 2));
            }
            for (var i = 0; i < 4; i++)
            {
                outpoint.TxId[i + 4] = (byte)(seed >> (i * 8));
            }

            return(outpoint);
        }