System.Random.NextDouble()

Here are the examples of the csharp api System.Random.NextDouble() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2239 Examples 7

19 View Source File : ViewModelsFactory.cs
License : MIT License
Project Creator : ABTSoftware

private static double[] GetRanromWalk(double valueShift)
        {
            var randomWalk = 1d;

            var yBuffer = new double[Count];
            for (var i = 0; i < Count; i++)
            {
                randomWalk += (Random.NextDouble() - 0.498);
                yBuffer[i] = randomWalk + valueShift;
            }

            return yBuffer;
        }

19 View Source File : FastPalettedScatterCharts.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void SetupScatterSeries()
        {
            var dataSeries = new XyDataSeries<double, double>() { AcceptsUnsortedData = true };

            var random = new Random(0);
            var dataPointColors = new List<Color>();

            for (int i = 0; i < 100000; i++)
            {
                dataSeries.Append(random.NextDouble(), random.NextDouble());
                dataPointColors.Add(GetRandomColor(random));
            }

            var scatterSeries = new ExtremeScatterRenderableSeries()
            {
                PointMarker = new EllipsePointMarker() {Width = 5, Height = 5}
            };
            sciChart.RenderableSeries.Add(scatterSeries);
            scatterSeries.DataSeries = dataSeries;
            scatterSeries.PaletteProvider = new TestPaletteProvider(dataPointColors);
        }

19 View Source File : HeatMapWithTextInCellsExampleView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries CreateSeries()
        {
            const int w = 24;
            const int h = 7;

            var rnd = new Random(0);
            var data = new double[h, w];

            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    data[y, x] = Math.Pow(rnd.NextDouble(), 0.15) * x / (w - 1) * y / (h - 1) * 100;
                }
            }

            return new UniformHeatmapDataSeries<int, int, double>(data, 0, 1, 0, 1);
        }

19 View Source File : SpectrogramDemoView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void UpdateXyDataSeries()
        {
            lock (this)
            {               
                for (int i = 0; i < 1024; i++)
                {
                    _re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                            5 * Math.Sin(2 * Math.PI * i / 10) +
                            2.0 * _random.NextDouble();
                    _im[i] = -10;
                }

                _transform.run(_re, _im);
                for (int i = 0; i < 1024; i++)
                {
                    double mag = Math.Sqrt(_re[i] * _re[i] + _im[i] * _im[i]);
                    _re[i] = 20 * Math.Log10(mag / 1024);
                    _im[i] = i;
                }

                _xyDataSeries.Clear();
                _xyDataSeries.Append(_im, _re);             
            }
        }

19 View Source File : ScatterChartPerformanceTest.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            // Create our data in another thread to stop the UI from being stalled. 
            // It's not appending to SciChart data series that is the problem, its Calling Rand.Next() two million times which is pretty slow :)
            TimedMethod.Invoke(() =>
            {
                var dataSeries = new XyDataSeries<double, double>() {AcceptsUnsortedData = true};
                var rand = new Random();

                // Allow 1M points in WPF/DirectX. In Silverlight or software rendering, 100k points is enough to stress the renderer
                int count = FeaturesHelper.Instance.SupportsHardwareAcceleration ? (int) 1E6 : (int) 1E5;

                // Append some data 
                for (int i = 0; i < count; i++)
                {
                    dataSeries.Append(rand.NextDouble(), rand.NextDouble());
                }

                // Bind to scichart 
                Action bindData = () => { BindData(dataSeries); };
                Dispatcher.BeginInvoke(bindData);

            }).After(200).OnThread(TimedMethodThread.Background).Go();
        }

19 View Source File : RealTimeGhostedTraces.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void TimerOnElapsed(object sender, EventArgs e)
        {
            var newDataSeries = new UniformXyDataSeries<double>(0d, 0.01);

            // Create a noisy sine wave and cache
            //  All this code is about the generation of data to create a nice randomized sine wave with 
            //  varying phase and amplitude
            double randomAmplitude = Constrain(_lastAmplitude + (_random.NextDouble() - 0.50), -2.0, 2.0);
            const double phase = 0.0;

            var noisySineWave = DataManager.Instance.GetNoisySinewaveYData(randomAmplitude, phase, 1000, 0.25);
            
            _lastAmplitude = randomAmplitude;

            // Append to a new dataseries
            newDataSeries.Append(noisySineWave);

            // Enqueue to the circular buffer
            _dataSeries.Add(newDataSeries);

            // Rereplacedign all DataSeries to RenderableSeries
            RereplacedignRenderableSeries(_dataSeries);
        }

19 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public DoubleSeries GenerateEEG(int count, ref double startPhase, double phaseStep)
        {
            var doubleSeries = new DoubleSeries();
            var rand = new Random((int)DateTime.Now.Ticks);

            for (int i = 0; i < count; i++)
            {
                var xyPoint = new XYPoint();

                var time = i / (double)count;
                xyPoint.X = time;
                //double mod = 0.2 * Math.Sin(startPhase);
                xyPoint.Y = //mod * Math.Sin(startPhase / 4.9) +
                             0.05 * (rand.NextDouble() - 0.5) +
                             1.0;

                doubleSeries.Add(xyPoint);
                startPhase += phaseStep;
            }

            return doubleSeries;
        }

19 View Source File : SeriesCustomTooltips3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void Initialize()
        {
            var xyzDataSeries3D = new XyzDataSeries3D<double>();

            for (int i = 0, pointIndex = 0; i < Count; i++)
            {
                var m1 = _random.Next(2) == 0 ? -1 : 1;
                var m2 = _random.Next(2) == 0 ? -1 : 1;
                var x1 = _random.NextDouble() * m1;
                var x2 = _random.NextDouble() * m2;

                if (x1 * x1 + x2 * x2 > 1) continue;

                var x = 2 * x1 * Math.Sqrt(1 - x1 * x1 - x2 * x2);
                var y = 2 * x2 * Math.Sqrt(1 - x1 * x1 - x2 * x2);
                var z = 1 - 2 * (x1 * x1 + x2 * x2);

                // Append an XYZ Point with random color
                // Set the PointMetadata.Tag which we bind to in the View 
                xyzDataSeries3D.Append(x, y, z, new PointMetadata3D(GetRandomColor(), 3.0f, false, 
                    string.Format("PointMetadata Index {0}", ++pointIndex)));
            }

            SciChart.RenderableSeries[0].DataSeries = xyzDataSeries3D;
        }

19 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public double[] GetRandomDoubleData(int pointCount)
        {
            var doubleData = new double[pointCount];

            double amplitude = _random.NextDouble() + 0.5;
            double freq = Math.PI * (_random.NextDouble() + 0.5) * 10;
            double offset = _random.NextDouble() - 0.5;

            for(int i = 0; i < pointCount; i++)
            {
                doubleData[i] = offset + (amplitude * Math.Sin(freq * i));
            }

            return doubleData;
        }

19 View Source File : CreateAWaterfall3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void FillDataSeries(WaterfallDataSeries3D<double> dataSeries, int sliceCount, int pointsPerSlice)
        {
            var count = pointsPerSlice * 2;
            var re = new double[count];
            var im = new double[count];

            for (int sliceIndex = 0; sliceIndex < sliceCount; ++sliceIndex)
            {
                for (var i = 0; i < count; i++)
                {
                    re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                            5 * Math.Sin(2 * Math.PI * i / 10) +
                            2.0 * _random.NextDouble();
                    im[i] = -10;
                }

                _transform.run(re, im);

                var scaleCoef = Math.Pow(1.5, sliceIndex * 0.3) / Math.Pow(1.5, sliceCount * 0.3);
                for (var pointIndex = 0; pointIndex < pointsPerSlice; pointIndex++)
                {
                    var mag = Math.Sqrt(re[pointIndex] * re[pointIndex] + im[pointIndex] * im[pointIndex]);
                    var yVal = _random.Next(10,20) * Math.Log10(mag / pointsPerSlice);
                    yVal = (yVal < -25 || yVal > -5)
                        ? (yVal < -25) ? -25 : _random.Next(-6, -3)
                        : yVal;

                    dataSeries[sliceIndex, pointIndex] = -yVal * scaleCoef;
                }
            }
        }

19 View Source File : CustomTooltipsWithModifiers.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries FillData(IUniformXyDataSeries<double> dataSeries, string name)
        {
            var randomWalk = 10.0;

            // Generate the Y data with slightly positively biased random walk on the Y-Axis
            var yBuffer = new double[Count];

            for (int i = 0; i < Count; i++)
            {
                randomWalk += _random.NextDouble() - 0.498;
                yBuffer[i] = randomWalk;
            }

            // Buffer above and append all in one go to avoid multiple recalculations of series range
            dataSeries.Append(yBuffer);
            dataSeries.SeriesName = name;

            return dataSeries;
        }

19 View Source File : SeriesBindingViewModel.cs
License : MIT License
Project Creator : ABTSoftware

private IEnumerable<BoxPoint> GetBoxPlotData()
        {
            var dates = Enumerable.Range(0, PointsCount).Select(i => i).ToArray();
            var medianValues = new RandomWalkGenerator(0).GetRandomWalkSeries(PointsCount).YData;
            var random = new Random(0);

            for (int i = 0; i < PointsCount; i++)
            {
                double med = medianValues[i];
                double min = med - random.NextDouble();
                double max = med + random.NextDouble();
                double lower = (med - min)*random.NextDouble() + min;
                double upper = (max - med)*random.NextDouble() + med;

                yield return new BoxPoint(dates[i], min, lower, med, upper, max);
            }
        }

19 View Source File : EEGExampleViewModel.cs
License : MIT License
Project Creator : ABTSoftware

private void OnTick(object sender, EventArgs e)
        {
            // Ensure only one timer Tick processed at a time
            lock (_syncRoot)
            {
                foreach (var channel in _channelViewModels)
                {
                    var dataSeries = channel.ChannelDataSeries;

                    using (dataSeries.SuspendUpdates())
                    {
                        // Add points 10 at a time for efficiency
                        for (int j = 0; j < BufferSize; j++)
                        {
                            // Append a new Y value in the random walk
                            dataSeries.Append(_random.NextDouble());
                        }
                    }

                    // For reporting current size to GUI
                    _currentSize = dataSeries.Count;
                }
            }
        }

19 View Source File : UsePointMarkers.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void UsePointMarkers_OnLoaded(object sender, RoutedEventArgs e)
        {
            var dataSeries1 = new UniformXyDataSeries<double> { SeriesName = "Ellipse Marker" };
            var dataSeries2 = new UniformXyDataSeries<double> { SeriesName = "Square Marker" };
            var dataSeries3 = new UniformXyDataSeries<double> { SeriesName = "Triangle Marker" };
            var dataSeries4 = new UniformXyDataSeries<double> { SeriesName = "Cross Marker" };
            var dataSeries5 = new UniformXyDataSeries<double> { SeriesName = "Sprite Marker" };

            const int dataSize = 30;
            var rnd = new Random(0);

            for (int i = 0; i < dataSize; i++) dataSeries1.Append(rnd.NextDouble());
            for (int i = 0; i < dataSize; i++) dataSeries2.Append(1 + rnd.NextDouble());
            for (int i = 0; i < dataSize; i++) dataSeries3.Append(1.8 + rnd.NextDouble());
            for (int i = 0; i < dataSize; i++) dataSeries4.Append(2.5 + rnd.NextDouble());
            for (int i = 0; i < dataSize; i++) dataSeries5.Append(3.5 + rnd.NextDouble());

            // insert a break into the line - we do this to test double.NaN for the point marker types 
            dataSeries1.Update(15, double.NaN);
            dataSeries2.Update(15, double.NaN);
            dataSeries3.Update(15, double.NaN);
            dataSeries4.Update(15, double.NaN);
            dataSeries5.Update(15, double.NaN);

            using (sciChart.SuspendUpdates())
            {
                lineSeries1.DataSeries = dataSeries1;
                lineSeries2.DataSeries = dataSeries2;
                lineSeries3.DataSeries = dataSeries3;
                lineSeries4.DataSeries = dataSeries4;
                lineSeries5.DataSeries = dataSeries5;
            }

            sciChart.ZoomExtents();
        }

19 View Source File : ViewModel3DFactory.cs
License : MIT License
Project Creator : ABTSoftware

private static WaterfallDataSeries3D<double> GereplacederfallDataSeries()
        {
            var pointsPerSlice = 100;
            var sliceCount = 20;

            var logBase = 10;
            var slicePositions = new double[sliceCount];
            for (int i = 0; i < sliceCount; ++i)
            {
                slicePositions[i] = i;
            }

            var dataSeries = new WaterfallDataSeries3D<double>(pointsPerSlice, slicePositions);
            dataSeries.StartX = 10;
            dataSeries.StepX = 1;

            _transform.init((uint)Math.Log(pointsPerSlice, 2));

            var count = pointsPerSlice * 2;
            var re = new double[count];
            var im = new double[count];

            for (int sliceIndex = 0; sliceIndex < sliceCount; ++sliceIndex)
            {
                for (var i = 0; i < count; i++)
                {
                    re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                            5 * Math.Sin(2 * Math.PI * i / 10) +
                            2.0 * _random.NextDouble();
                    im[i] = -10;
                }

                _transform.run(re, im);

                var scaleCoef = Math.Pow(1.5, sliceIndex * 0.3) / Math.Pow(1.5, sliceCount * 0.3);
                for (var pointIndex = 0; pointIndex < pointsPerSlice; pointIndex++)
                {
                    var mag = Math.Sqrt(re[pointIndex] * re[pointIndex] + im[pointIndex] * im[pointIndex]);
                    var yVal = _random.Next(10, 20) * Math.Log10(mag / pointsPerSlice);
                    yVal = (yVal < -25 || yVal > -5)
                        ? (yVal < -25) ? -25 : _random.Next(-6, -3)
                        : yVal;

                    dataSeries[sliceIndex, pointIndex] = -yVal * scaleCoef;
                }
            }

            return dataSeries;
        }

19 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public DoubleSeries GetNoisySinewave(double amplitude, double phase, int pointCount, double noiseAmplitude)
        {
            var sinewave = GetSinewave(amplitude, phase, pointCount);

            // Add some noise
            for (int i = 0; i < pointCount; i++)
            {
                sinewave[i].Y += (_random.NextDouble() * noiseAmplitude) - (noiseAmplitude * 0.5);
            }

            return sinewave;
        }

19 View Source File : BoxPlotExampleView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private IEnumerable<BoxPoint> GetBoxPlotData(int count)
        {
            var dates = Enumerable.Range(0, count).Select(i => new DateTime(2011, 01, 01).AddMonths(i)).ToArray();
            var medianValues = new RandomWalkGenerator(0).GetRandomWalkSeries(count).YData;

            var random = new Random(0);
            for (int i = 0; i < count; i++)
            {
                double med = medianValues[i];

                double min = med - random.NextDouble();
                double max = med + random.NextDouble();

                double lower = (med - min)*random.NextDouble() + min;
                double upper = (max - med)*random.NextDouble() + med;

                yield return new BoxPoint(dates[i], min, lower, med, upper, max);
            }
        }

19 View Source File : MainViewModel.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries GetData()
        {
            var xyDataSeries = new XyDataSeries<double>();
            var random = new Random((int)DateTime.UtcNow.Ticks);
            var phase = (random.NextDouble() + 0.5) * 10;
            for (int i = 0; i < 100; i++)
            {
                xyDataSeries.Append(i, Math.Sin(i * phase));
            }

            return xyDataSeries;
        }

19 View Source File : TestAmf3Writer.cs
License : MIT License
Project Creator : a1q123456

[TestMethod]
        public void TestDouble()
        {
            var reader = new Amf3Reader();
            var writer = new Amf3Writer();
            var random = new Random();

            using (var sc = new SerializationContext())
            {
                for (int i = 0; i < 1000; i++)
                {
                    var value = random.NextDouble();

                    writer.WriteBytes(value, sc);
                    var buffer = new byte[sc.MessageLength];
                    sc.GetMessage(buffer);
                    reader.TryGetDouble(buffer, out var readValue, out var consumed);
                    replacedert.AreEqual(readValue, value);
                    replacedert.AreEqual(consumed, buffer.Length);
                }
            }
        }

19 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public DoubleSeries GetRandomDoubleSeries(int pointCount)
        {
            var doubleSeries = new DoubleSeries();

            double amplitude = _random.NextDouble() + 0.5;
            double freq = Math.PI * (_random.NextDouble() + 0.5) * 10;
            double offset = _random.NextDouble() - 0.5;

            for(int i = 0; i < pointCount; i++)
            {
                doubleSeries.Add(new XYPoint() { X=i, Y=offset + amplitude*Math.Sin(freq*i) });
            }

            return doubleSeries;
        }

19 View Source File : UniformHeatmapPeakDetection.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private double[,] GetSpectrogramBuffer()
        {
            const int yCount = 100;
            const int xCount = 4_096;
            var spectrogramBuffer = new double[yCount, xCount];

            var random = new Random();
            var transform = new FFT2();
            transform.init(12);

            var re = new double[xCount];
            var im = new double[xCount];
            for (int y = 0; y < yCount; y++)
            {
                for (int i = 0; i < xCount; i++)
                {
                    re[i] = 2d * Math.Sin(2 * Math.PI * i / 20) +
                            5 * Math.Sin(2 * Math.PI * i / 10) -
                            2d * random.NextDouble();
                    im[i] = -10;
                }

                transform.run(re, im);

                for (int i = 0; i < xCount; i++)
                {
                    var mag = Math.Sqrt(re[i] * re[i] + im[i] * im[i]);
                    im[i] = i;

                    spectrogramBuffer[y, i] = 20 * Math.Log10(mag / xCount);
                }
            }

            return spectrogramBuffer;
        }

19 View Source File : Rand.cs
License : MIT License
Project Creator : ABTSoftware

public static float Next()
        {
            return (float)StaticRandom.NextDouble();
        }

19 View Source File : CreateABubble3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            var xyzDataSeries3D = new XyzDataSeries3D<double>() {SeriesName = "Colorful Bubble!"};

            const int count = 250;

            var random = new Random(0);

            DataManager.Instance.SetRandomSeed(0); // required only by some UIAutomationTests, to have consistent results between test runs 
            for (var i = 0; i < count; i++)
            {
                var x = DataManager.Instance.GetGaussianRandomNumber(5, 1.5);
                var y = DataManager.Instance.GetGaussianRandomNumber(5, 1.5);
                var z = DataManager.Instance.GetGaussianRandomNumber(5, 1.5);

                // Scale is a multiplier used to increase/decrease ScatterRenderableSeries3D.ScatterPointSize
                var scale = (float) ((random.NextDouble() + 0.5)*3.0);

                // Color is applied to PointMetadata3D and overrides the default ScatterRenderableSeries.Stroke property
                Color? randomColor = Color.FromArgb(0xFF, (byte) random.Next(50, 255), (byte) random.Next(50, 255), (byte) random.Next(50, 255));
                
                // To declare scale and colour, add a VertextData clreplaced as the w (fourth) parameter. 
                // The PointMetadata3D clreplaced also has other properties defining the behaviour of the XYZ point
                xyzDataSeries3D.Append(x, y, z, new PointMetadata3D(randomColor, scale));
            }

            ScatterSeries3D.DataSeries = xyzDataSeries3D;

            PointMarkerCombo.SelectedIndex = 0;
        }

19 View Source File : WaterfallChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private XyDataSeries<double, double> UpdateXyDataSeries()
        {
            var doubleSeries = new XyDataSeries<double, double>();

            var _re = new double[1024];
            var _im = new double[1024];

            for (var i = 0; i < 1024; i++)
            {
                _re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                         5 * Math.Sin(2 * Math.PI * i / 10) +
                         2.0 * _random.NextDouble();
                _im[i] = -10;
            }

            _transform.run(_re, _im);
            var _re2 = new double[500];
            var _im2 = new double[500];
            for (var i = 0; i < 500; i++)
            {
                var mag = Math.Sqrt(_re[i] * _re[i] + _im[i] * _im[i]);
                var yVal = 20 * Math.Log10(mag / 500);
                _re2[i] = (yVal < -25 || yVal > -5)
                    ? (yVal < -25) ? -25 : _random.Next(-6, -3)
                    : yVal;

                _im2[i] = i;
            }
            _re2[0] = -25;
            doubleSeries.Append(_im2, _re2);

            return doubleSeries;
        }

19 View Source File : CreateAPointLine3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            var xyzDataSeries3D = new XyzDataSeries3D<double>();

            var random = new Random(0);

            for (var i = 0; i < Count; i++)
            {
                var x = 5*Math.Sin(i);
                var y = i;
                var z = 5*Math.Cos(i);

                Color? randomColor = Color.FromArgb(0xFF, (byte) random.Next(50, 255), (byte) random.Next(50, 255), (byte) random.Next(50, 255));
                var scale = (float) ((random.NextDouble() + 0.5)*3.0);

                xyzDataSeries3D.Append(x, y, z, new PointMetadata3D(randomColor, scale));
            }

            PointLineSeries3D.DataSeries = xyzDataSeries3D;
        }

19 View Source File : HeatMapExampleView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries CreateSeries(int index, int width, int height, double cpMin, double cpMax)
        {
            var seed = SeriesAnimationBase.GlobalEnableAnimations ? (Environment.TickCount << index) : 0;
            var random = new Random(seed);
            double angle = Math.Round(Math.PI * 2 * index, 3) / seriesPerPeriod;
            int w = width, h = height;
            var data = new double[h, w];
            for (int x = 0; x < w; x++)
                for (int y = 0; y < h; y++)
                {
                    var v = (1 + Math.Round(Math.Sin(x * 0.04 + angle), 3)) * 50 + (1 + Math.Round(Math.Sin(y * 0.1 + angle), 3)) * 50 * (1 + Math.Round(Math.Sin(angle * 2), 3));
                    var cx = w / 2; var cy = h / 2;
                    var r = Math.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
                    var exp = Math.Max(0, 1 - r * 0.008);
                    var zValue = (v * exp + random.NextDouble() * 50);
                    data[y, x] = (zValue > cpMax) ? cpMax : zValue;
                }
            return new UniformHeatmapDataSeries<int, int, double>(data, 0, 1, 0, 1);
        }

19 View Source File : ScrollBars.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries FillData(IXyDataSeries<DateTime, double> dataSeries, string name)
        {
            double randomWalk = 10.0;
            var startDate = new DateTime(2012, 01, 01);

            // Generate the X,Y data with sequential dates on the X-Axis and slightly positively biased random walk on the Y-Axis
            var xBuffer = new DateTime[Count];
            var yBuffer = new double[Count];
            for (int i = 0; i < Count; i++)
            {
                randomWalk += (_random.NextDouble() - 0.498);
                yBuffer[i] = randomWalk;
                xBuffer[i] = startDate.AddMinutes(i * 10);
            }

            // Buffer above and append all in one go to avoid multiple recalculations of series range
            dataSeries.Append(xBuffer, yBuffer);
            dataSeries.SeriesName = name;

            return dataSeries;
        }

19 View Source File : ViewModel3DFactory.cs
License : MIT License
Project Creator : ABTSoftware

private static XyzDataSeries3D<double> GetScaledDataSeries()
        {
            var xyzDataSeries3D = new XyzDataSeries3D<double>();

            const int count = 250;

            var random = new Random(0);

            for (var i = 0; i < count; i++)
            {
                var x = DataManager.Instance.GetGaussianRandomNumber(40, 19);
                var y = DataManager.Instance.GetGaussianRandomNumber(5, 1.5);
                var z = DataManager.Instance.GetGaussianRandomNumber(10, 5);

                var scale = (float)((random.NextDouble() + 0.5) * 3.0);

                Color? randomColor = Color.FromArgb(0xFF, (byte)random.Next(50, 255), (byte)random.Next(50, 255), (byte)random.Next(50, 255));

                xyzDataSeries3D.Append(x, y, z, new PointMetadata3D(randomColor, scale));
            }

            return xyzDataSeries3D;
        }

19 View Source File : Rand.cs
License : MIT License
Project Creator : ABTSoftware

public float NextWalk()
        {
            // Random walk
            _current += (float)((InstanceRandom.NextDouble() - 0.5) * 0.002);

            // Clamp to 0..1
            _current = Math.Max(Math.Min(_current, 1.0f), 0.0f);
            return _current;
        }

19 View Source File : RealtimeOrthogonalHeatmap3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnNewData(object sender, EventArgs e)
        {
            _tick++;
            if (_tick == 2)
            {
                _tick = 0;
                _step = _random.Next(0, 11);
            }

            var mreplacedVal = new double[100];

            for (int i = 0; i < 100; i++)
            {
                double y = _step * Math.Sin(((2 * Math.PI) * 0.4) * t) + _random.NextDouble() * 2;
                _yValues[i] = y;
                _tValues[i] = t;
                mreplacedVal[i] = y + 10;                

                t += dt;
            }

            var sortData = mreplacedVal.OrderByDescending(x => x);

            using (_series0.SuspendUpdates())
            using (_series1.SuspendUpdates())
            using (_series2.SuspendUpdates())
            {
                _series0.Append(_tValues, _yValues);
                _series1.PushRow(sortData.ToArray());
                _series2.PushRow(sortData.ToArray());
            }
        }

19 View Source File : SpectrumAnalyzerExampleViewModel.cs
License : MIT License
Project Creator : ABTSoftware

private void UpdateData()
        {
            lock (this)
            {                
                for (int i = 0; i < Count; i++)
                {
                    _re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                            5.0 * Math.Sin(2 * Math.PI * i / 10) +
                            2.0 * _random.NextDouble();
                    _im[i] = IsFrequencyDomain ? 0.0 : i;
                }

                if (IsFrequencyDomain)
                {
                    _transform.run(_re, _im);
                    for (int i = 0; i < Count; i++)
                    {
                        double mag = Math.Sqrt(_re[i] * _re[i] + _im[i] * _im[i]);
                        _re[i] = 20 * Math.Log10(mag / Count);
                        _im[i] = i;
                    }
                }                

                _dataSeries.SeriesName = YAxisreplacedle;
                _dataSeries.Clear();
                _dataSeries.Append(_im, _re);
            }
        }

19 View Source File : RealtimeFifoChartView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnNewData(object sender, EventArgs e)
        {
            // Compute our three series values
            double y1 = 3.0 * Math.Sin(2 * Math.PI * 1.4 * t) + _random.NextDouble() * 0.5;
            double y2 = 2.0 * Math.Cos(2 * Math.PI * 0.8 * t) + _random.NextDouble() * 0.5;
            double y3 = 1.0 * Math.Sin(2 * Math.PI * 2.2 * t) + _random.NextDouble() * 0.5;

            // Suspending updates is optional, and ensures we only get one redraw
            // once all three dataseries have been appended to
            using (sciChart.SuspendUpdates())
            {
                // Append x,y data to previously created series
                series0.Append(y1);
                series1.Append(y2);
                series2.Append(y3);
            }

            // Increment current time
            t += dt;
        }

19 View Source File : RealTimePerformanceDemoView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void DataAppendLoop()
        {
            // By nesting multiple updates inside a SuspendUpdates using block, you get one redraw at the end
            using (sciChart.SuspendUpdates())
            {
                // Preload previous value with k-1 sample, or 0.0 if the count is zero
                int xValue = _mainSeries.Count > 0 ? _mainSeries.XValues[_mainSeries.Count - 1] : 0;
                double yValue = _mainSeries.Count > 0 ? _mainSeries.YValues[_mainSeries.Count - 1] : 10.0f;

                // Add N points at a time. We want to get to the higher point counts 
                // quickly to demonstrate performance. 
                // Also, it is more efficient to buffer and block update the chart
                // even if you use SuspendUpdates due to the overhead of calculating min, max
                // for a series
                for (int i = 0; i < BufferSize; i++)
                {
                    // Generate a new X,Y value in the random walk and buffer
                    xValue++;
                    yValue += _random.NextDouble() - 0.5;

                    xBuffer[i] = xValue;
                    yBuffer[i] = (float)yValue;

                    // Update moving averages
                    maLowBuffer[i] = (float)_maLow.Push(yValue).Current;
                    maHighBuffer[i] = (float)_maHigh.Push(yValue).Current;
                }

                // Append block of values to all three series
                _mainSeries.Append(xBuffer, yBuffer);
                _maLowSeries.Append(xBuffer, maLowBuffer);
                _maHighSeries.Append(xBuffer, maHighBuffer);
            }
        }

19 View Source File : TestAmf0Writer.cs
License : MIT License
Project Creator : a1q123456

[TestMethod]
        public void TestNumber()
        {
            var random = new Random();
            var writer = new Amf0Writer();
            var reader = new Amf0Reader();
            using (var sc = new SerializationContext())
            {
                for (int i = 0; i < 1000; i++)
                {
                    var num = random.NextDouble() * 10 - 5;
                    writer.WriteBytes(num, sc);
                    var buffer = new byte[sc.MessageLength];
                    sc.GetMessage(buffer);

                    reader.TryGetNumber(buffer, out var readValue, out var consumed);
                    replacedert.AreEqual(num, readValue);
                    replacedert.AreEqual(buffer.Length, consumed);
                }
            }
        }

19 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public double GetGaussianRandomNumber(double mean, double stdDev)
        {
            double u1 = _random.NextDouble(); //these are uniform(0,1) random doubles
            double u2 = _random.NextDouble();
            double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *
                         Math.Sin(2.0 * Math.PI * u2); //random normal(0,1)
            double randNormal =
                         mean + stdDev * randStdNormal; //random normal(mean,stdDev^2)
            return randNormal;
        }

19 View Source File : RealTimePolarChartExampleView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void TimerOnElapsed(object sender, EventArgs e)
        {
            var newDataSeries = new XyDataSeries<double, double>();

            // Create a noisy sine wave and cache
            // All this code is about the generation of data to create a nice randomized sine wave with 
            // varying phase and amplitude
            var randomAmplitude = Constrain(_lastAmplitude + (_random.NextDouble() - 0.50) / 2, -2.0, 2.0);
            const double phase = 0.0;

            var noisySineWave = DataManager.Instance.GetNoisySinewave(randomAmplitude, phase, 1000, 0.25);
            _lastAmplitude = randomAmplitude;

            // Append to a new dataseries
            newDataSeries.Append(noisySineWave.XData, noisySineWave.YData);

            lineSeries.DataSeries = newDataSeries;
        }

19 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public double[] GetNoisySinewaveYData(double amplitude, double phase, int pointCount, double noiseAmplitude)
        {
            var sinewave = GetSinewaveYData(amplitude, phase, pointCount);

            // Add some noise
            for (int i = 0; i < pointCount; i++)
            {
                sinewave[i] += (_random.NextDouble() * noiseAmplitude) - (noiseAmplitude * 0.5);
            }

            return sinewave;
        }

19 View Source File : ThemeManager3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void ThemeManager3DChart_OnLoaded(object sender, RoutedEventArgs e)
        {
            scatterSeries3D.PointMarker = new PyramidPointMarker3D();
            var xyzDataSeries3D = new XyzDataSeries3D<double>();

            int count = 150;

            var random = new Random(0);

            for (int i = 0; i < count; i++)
            {
                double x = DataManager.Instance.GetGaussianRandomNumber(5, 1.5);
                double y = DataManager.Instance.GetGaussianRandomNumber(5, 1.5);
                double z = DataManager.Instance.GetGaussianRandomNumber(5, 1.5);

                // Scale is a multiplier used to increase/decrease ScatterRenderableSeries3D.ScatterPointSize
                float scale = (float)((random.NextDouble() + 0.5) * 3.0);

                // Color is applied to PointMetadata3D and overrides the default ScatterRenderableSeries.Stroke property
                Color? randomColor = Color.FromArgb(0xFF, (byte)random.Next(50, 255), (byte)random.Next(50, 255), (byte)random.Next(50, 255));

                // To declare scale and colour, add a VertextData clreplaced as the w (fourth) parameter. 
                // The PointMetadata3D clreplaced also has other properties defining the behaviour of the XYZ point
                xyzDataSeries3D.Append(x, y, z, new PointMetadata3D(randomColor, scale));
            }

            scatterSeries3D.DataSeries = xyzDataSeries3D;
        }

19 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public DoubleSeries GetSquirlyWave()
        {
            var doubleSeries = new DoubleSeries();
            var rand = new Random(0);

            const int COUNT = 1000;
            for (int i = 0; i < COUNT; i++)            
            {
                var xyPoint = new XYPoint();

                var time = i / (double)COUNT;
                xyPoint.X = time;
                xyPoint.Y = time * Math.Sin(2 * Math.PI * i / (double)COUNT) +
                             0.2 * Math.Sin(2 * Math.PI * i / (COUNT / 7.9)) +
                             0.05 * (rand.NextDouble() - 0.5) +
                             1.0;

                doubleSeries.Add(xyPoint);
            }

            return doubleSeries;
        }

19 View Source File : FiltersAPIExample.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private DoubleSeries CreateSomeScatterData(double randomness, double curviness)
        {
            var doubleSeries = new DoubleSeries();
            Random r = new Random(0);
            const double c = 0;
            const double m = 0.02;

            // Create some data which looks like a scatter chart with points randomly spaced around a 
            // slightly curved / linear trendline dataset 
            // 
            // this will be used to apply filters such as Trendline, Polynomial, Scale, Offset etc... 
            for (int x = 0; x < 200; x++)
            {
                double y = (m * x + c + (r.NextDouble() * randomness)) * x * (1 + curviness);
                doubleSeries.Add(new XYPoint { X = x, Y = y });
            }

            return doubleSeries;
        }

19 View Source File : EliminatingFlicker.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnTimerTick(object sender, EventArgs e)
        {
            _yNext = _yNext + ((float)_random.NextDouble() - 0.5f);

            using (_xyDataSeries.SuspendUpdates())
            {                
                if (_index == 999)
                {
                    // wrap around. Break the line with nan
                    _xyDataSeries.Append(_index+1, float.NaN);
                    _index = 0;
                }

                _xyDataSeries.Update(_index++, _yNext);
            }
        }

19 View Source File : Math.cs
License : MIT License
Project Creator : 1CM69

public static double RandomReal()
    {
      lock (Math.RndObject)
        return Math.RndObject.NextDouble();
    }

19 View Source File : World.cs
License : MIT License
Project Creator : ABTSoftware

public double NextRandomDouble()
        {
            lock (_rng)
            {
                return _rng.NextDouble();
            }
        }

19 View Source File : UniformHeatmapAndPaletteProvider.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries CreateSeries()
        {
            double angle = Math.Round(Math.PI * 2 * 1 / 30, 3);
            int w = 300, h = 200;
            var data = new double[h, w];
            for (int x = 0; x < w; x++)
                for (int y = 0; y < h; y++)
                {
                    var v = (1 + Math.Round(Math.Sin(x * 0.04 + angle), 3)) * 50 + (1 + Math.Round(Math.Sin(y * 0.1 + angle), 3)) * 50 * (1 + Math.Round(Math.Sin(angle * 2), 3));
                    var cx = 150; var cy = 100;
                    var r = Math.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
                    var exp = Math.Max(0, 1 - r * 0.008);
                    data[y, x] = (v * exp + _random.NextDouble() * 50);
                }

            var xStart = new DateTime(2017, 1, 13, 0, 0, 0);
            var xStep = DateTime.MinValue.AddDays(1).AddHours(6).AddMinutes(30);
            return new UniformHeatmapDataSeries<DateTime, int, double>(data, xStart, xStep, 0, 2) { SeriesName = "UniformHeatmap" };
        }

19 View Source File : LogarithmicAxis3DView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            var converter = new LogarithmicBase3DConverter();
            var logBinding = new Binding("SelectedValue") { ElementName = "logBasesChbx", Converter = converter };

            logarithmicNumericYAxis3D.SetBinding(LogarithmicNumericAxis3D.LogarithmicBaseProperty, logBinding);
            logarithmicNumericXAxis3D.SetBinding(LogarithmicNumericAxis3D.LogarithmicBaseProperty, logBinding);

            var xyzDataSeries3D = new XyzDataSeries3D<double>();
            var data = DataManager.Instance.GetExponentialCurve(1.8, 100);

            int count = 100;
            var random = new Random(0);

            for (int i = 0; i < count; i++)
            {
                double x = data[i].X;
                double y = data[i].Y;
                double z = DataManager.Instance.GetGaussianRandomNumber(15, 1.5);

                Color? randomColor = Color.FromArgb(0xFF, (byte)random.Next(50, 255), (byte)random.Next(50, 255), (byte)random.Next(50, 255));
                float scale = (float)((random.NextDouble() + 0.5) * 3.0);

                xyzDataSeries3D.Append(x, y, z, new PointMetadata3D(randomColor, scale));
            }

            pointLineSeries3D.DataSeries = xyzDataSeries3D;
        }

19 View Source File : Tunneler.cs
License : MIT License
Project Creator : 1upD

public override void Step(AlifeMap map)
        {
            try {
                int seed = this.X + this.Y + this.Z + (int)this.Direction + this.Height + this.Width + (int)System.DateTime.Now.Ticks;

                // Get random number
                Random random = new Random(seed);
                double sample = random.NextDouble();

                // Check turn probability. If turning, change direction 90 degrees
                if (sample < this.ProbTurn)
                {
                    sample = random.NextDouble();
                    int polarity = sample > 0.5 ? 1 : -1;
                    this.Direction = AlifeDirectionOperations.Add(this.Direction, polarity);
                }

                // Get new random seed
                sample = random.NextDouble();

                // Check reproduction probability
                if (sample < this.ProbReproduce)
                {
                    sample = random.NextDouble();
                    int polarity = sample > 0.5 ? 1 : -1;
                    AlifeDirection childDirection = AlifeDirectionOperations.Add(this.Direction, polarity);
                    int widthDecay = random.Next(this.MinWidthDecayRate, this.MaxWidthDecayRate);
                    int heightDecay = random.Next(this.MinHeightDecayRate, this.MaxHeightDecayRate);
                    Tunneler child = new Tunneler(this.Style, this.X, this.Y, this.Z, this.Width - widthDecay, this.Height - heightDecay, this.MaxLifetime - this.LifetimeDecayRate, this.MaxLifetime - this.LifetimeDecayRate, this.ProbReproduce, this.ProbTurn, this.ProbAscend, childDirection);
                    map.Agents.Add(child);
                }
                else
                {
                    sample = random.NextDouble();
                    if (sample < this.ProbSpawnRoomer)
                    {
                        Roomer child = new Roomer(x: this.X, y: this.Y, z: this.Z, style: this.Style, height: Math.Max(this.Height, 2), maxWidth: Math.Min(this.Width * 2, 3), mustDeploy: false);
                        map.Agents.Add(child);
                        }
                }

                // Get new random seed
                sample = random.NextDouble();

                // Check a s c e n d probability
                if (sample < this.ProbAscend)
                {
                    sample = random.NextDouble();
                        int verticalDistance = random.Next(1, Math.Min(this.Height, this.MaxVerticalDrop));
                    int polarity = sample > 0.5 ? verticalDistance : -verticalDistance;
                    this.Z += polarity;
                }
                else
                {
                    // Update location
                    switch (this.Direction)
                    {
                        case AlifeDirection.East:
                            this.X++;
                            break;
                        case AlifeDirection.North:
                            this.Y++;
                            break;
                        case AlifeDirection.West:
                            this.X--;
                            break;
                        case AlifeDirection.South:
                            this.Y--;
                            break;
                        case AlifeDirection.Up:
                            this.Z++;
                            break;
                        case AlifeDirection.Down:
                            this.Z--;
                            break;
                    }

                }


                // Mark location
                // Nasty nested four loop to handle the added spaces from the height and width
                bool vertical = this.Direction == AlifeDirection.North || this.Direction == AlifeDirection.South;
                for (int x = this.X; x <= (vertical ? this.X + this.Width : this.X); x++)
                {
                    for (int y = this.Y; y <= (vertical ? this.Y : this.Y + this.Width); y++)
                    {
                        for (int z = this.Z; z <= this.Z + this.Height; z++)
                        {
                            map.MarkLocation(this.Style, x, y, z);
                        }
                    }
                }

            if (this.Lifetime == 1 && this.SpawnRoomerOnDeath)
            {
                    log.Debug(string.Format("Tunneler died at {0}, {1}, {2}.", this.X, this.Y, this.Z));

                    // Add a roomer
                    Roomer child = new Roomer(x: this.X, y: this.Y, z: this.Z, style: this.Style, height: Math.Max(this.Height, 2), maxWidth: Math.Min(this.Width * 2, 3));
                    map.Agents.Add(child);
                }

            this.Lifetime--;
            }
            catch (Exception e){
                log.Error("Error in Tunneler Step function: ", e);
            }
        }

19 View Source File : MicroVM.CPU.cs
License : MIT License
Project Creator : a-downing

public bool Cycle(out Status status, int numCycles = 1) {
            savedStatus = Status.UNDEFINED;

            for(int i = 0; i < numCycles; i++) {
                if(savedStatus != Status.UNDEFINED) {
                    status = savedStatus;
                    return false;
                }

                if((flags & (uint)Flag.INTERRUPTS_ENABLED) != 0 && pendingInterrupts.Count != 0) {
                    uint addr = pendingInterrupts.Dequeue();

                    replacedignMemory(registers[(int)Register.SP], pc);
                    registers[(int)Register.SP] += 4;
                    pc = addr;

                    if(savedStatus != Status.UNDEFINED) {
                        status = savedStatus;
                        return false;
                    }
                }

                if(pc >= instructions.Length) {
                    status = Status.OUT_OF_INSTRUCTIONS;
                    return false;
                }

                uint inst = instructions[pc++];
                Opcode opcode = (Opcode)((inst & (uint)Instruction.OPCODE_MASK) >> (int)Instruction.OPCODE_SHIFT);
                Cond cond = (Cond)((inst & (int)Instruction.COND_MASK) >> (int)Instruction.COND_SHIFT);
                uint op1Flag = inst & (uint)Instruction.OP1_FLAG_MASK;
                uint op2Flag = inst & (uint)Instruction.OP2_FLAG_MASK;
                uint op3Flag = inst & (uint)Instruction.OP3_FLAG_MASK;
                uint immediate = 0;
                bool nextIsImmediate = false;

                /*Program.Print("");
                Program.PrintVar(nameof(pc), pc);
                Program.Print($"instruction: {opcode}.{cond}");
                Program.Print($"instruction bits: {Convert.ToString(inst, 2).PadLeft(32, '0')}");
                Program.Print($"flags: {Convert.ToString(flags & (uint)Flag.EQUAL, 2).PadLeft(32, '0')}");*/

                if(op1Flag == 0) {
                    immediate = inst & (uint)Instruction.IMM1_MASK;

                    if(immediate == (uint)Instruction.IMM1_MASK) {
                        nextIsImmediate = true;
                    }
                } else if(op2Flag == 0) {
                    immediate = inst & (uint)Instruction.IMM2_MASK;

                    if(immediate == (uint)Instruction.IMM2_MASK) {
                        nextIsImmediate = true;
                    }
                } else if(op3Flag == 0) {
                    immediate = inst & (uint)Instruction.IMM3_MASK;

                    if(immediate == (uint)Instruction.IMM3_MASK) {
                        nextIsImmediate = true;
                    }
                }

                if(nextIsImmediate) {
                    if(pc >= instructions.Length) {
                        status = Status.OUT_OF_INSTRUCTIONS;
                        return false;
                    }

                    immediate = instructions[pc++];
                }

                switch(cond) {
                    case Cond.EQ:
                        if((flags & (uint)Flag.EQUAL) != 0) {
                            break;
                        }

                        continue;
                    case Cond.NE:
                        if((flags & (uint)Flag.EQUAL) == 0) {
                            break;
                        }

                        continue;
                    case Cond.GT:
                        if((flags & (uint)Flag.GREATER_THAN) != 0) {
                            break;
                        }

                        continue;
                    case Cond.LT:
                        if((flags & (uint)Flag.LESS_THAN) != 0) {
                            break;
                        }

                        continue;
                    case Cond.GE:
                        if((flags & (uint)(Flag.GREATER_THAN | Flag.EQUAL)) != 0) {
                            break;
                        }

                        continue;
                    case Cond.LE:
                        if((flags & (uint)(Flag.LESS_THAN | Flag.EQUAL)) != 0) {
                            break;
                        }

                        continue;
                }

                bool handledHere = true;

                // zero arg instructions
                switch(opcode) {
                    case Opcode.NOP:
                        break;
                    case Opcode.RET:
                        registers[(int)Register.SP] -= 4;
                        pc = ReadMemory(registers[(int)Register.SP]).Uint;
                        break;
                    case Opcode.CLI:
                        flags &= ~(uint)Flag.INTERRUPTS_ENABLED;
                        break;
                    case Opcode.SEI:
                        flags |= (uint)Flag.INTERRUPTS_ENABLED;
                        break;
                    default:
                        handledHere = false;
                        break;
                }

                if(handledHere) {
                    continue;
                }

                uint op1 = (inst & (uint)Instruction.OP1_MASK) >> (int)Instruction.OP1_SHIFT;
                uint arg1 = (op1Flag != 0) ? registers[op1] : immediate;
                // just testing this, if it's not slower, arg1 will just be a Value32
                Value32 arg1v = new Value32 { Uint = arg1 };
                handledHere = true;

                /*Program.PrintVar(nameof(op1), op1);
                Program.PrintVar(nameof(op1Flag), op1Flag);
                Program.PrintVar(nameof(immediate), immediate);
                Program.PrintVar(nameof(arg1), arg1);*/

                // one arg instructions
                switch(opcode) {
                    case Opcode.JMP:
                        pc = arg1;
                        break;
                    case Opcode.CALL:
                        replacedignMemory(registers[(int)Register.SP], pc);
                        registers[(int)Register.SP] += 4;
                        pc = arg1;
                        break;
                    case Opcode.PUSH:
                        replacedignMemory(registers[(int)Register.SP], arg1);
                        registers[(int)Register.SP] += 4;
                        break;
                    case Opcode.POP:
                        registers[(int)Register.SP] -= 4;
                        registers[op1] = ReadMemory(registers[(int)Register.SP]).Uint;
                        break;
                    case Opcode.ITOF:
                        var itof = new Value32 { Uint = registers[op1] };
                        itof.Float = (float)itof.Int;
                        registers[op1] = itof.Uint;
                        break;
                    case Opcode.FTOI:
                        var ftoi = new Value32 { Uint = registers[op1] };
                        ftoi.Int = (int)ftoi.Float;
                        registers[op1] = ftoi.Uint;
                        break;
                    case Opcode.RNGI:
                        registers[op1] = (uint)random.Next();
                        break;
                    case Opcode.RNGF:
                        var rngf = new Value32 { Float = (float)random.NextDouble() };
                        registers[op1] = rngf.Uint;
                        break;
                    default:
                        handledHere = false;
                        break;
                }

                if(handledHere) {
                    continue;
                }

                uint op2 = (inst & (uint)Instruction.OP2_MASK) >> (int)Instruction.OP2_SHIFT;
                uint arg2 = (op2Flag != 0) ? registers[op2] : immediate;
                Value32 arg2v = new Value32 { Uint = arg2 };
                handledHere = true;

                /*Program.PrintVar(nameof(op2), op2);
                Program.PrintVar(nameof(op2Flag), op2Flag);
                Program.PrintVar(nameof(immediate), immediate);
                Program.PrintVar(nameof(arg2), arg2);*/

                // two arg instructions
                switch(opcode) {
                    case Opcode.MOV:
                        registers[op1] = arg2;
                        break;
                    case Opcode.CMPI:
                        flags = ((int)arg1 == (int)arg2) ? flags | (uint)Flag.EQUAL : flags & ~(uint)Flag.EQUAL;
                        flags = ((int)arg1 > (int)arg2) ? flags | (uint)Flag.GREATER_THAN : flags & ~(uint)Flag.GREATER_THAN;
                        flags = ((int)arg1 < (int)arg2) ? flags | (uint)Flag.LESS_THAN : flags & ~(uint)Flag.LESS_THAN;
                        break;
                    case Opcode.CMPU:
                        flags = (arg1 == arg2) ? flags | (uint)Flag.EQUAL : flags & ~(uint)Flag.EQUAL;
                        flags = (arg1 > arg2) ? flags | (uint)Flag.GREATER_THAN : flags & ~(uint)Flag.GREATER_THAN;
                        flags = (arg1 < arg2) ? flags | (uint)Flag.LESS_THAN : flags & ~(uint)Flag.LESS_THAN;
                        break;
                    case Opcode.CMPF:
                        flags = (arg1v.Float == arg2v.Float) ? flags | (uint)Flag.EQUAL : flags & ~(uint)Flag.EQUAL;
                        flags = (arg1v.Float > arg2v.Float) ? flags | (uint)Flag.GREATER_THAN : flags & ~(uint)Flag.GREATER_THAN;
                        flags = (arg1v.Float < arg2v.Float) ? flags | (uint)Flag.LESS_THAN : flags & ~(uint)Flag.LESS_THAN;
                        break;
                    default:
                        handledHere = false;
                        break;
                }

                if(handledHere) {
                    continue;
                }

                uint op3 = (inst & (uint)Instruction.OP3_MASK) >> (int)Instruction.OP3_SHIFT; 
                uint arg3 = (op3Flag != 0) ? registers[op3] : immediate;
                Value32 arg3v = new Value32 { Uint = arg3 };
                handledHere = true;

                /*Program.PrintVar(nameof(op3), op3);
                Program.PrintVar(nameof(op3Flag), op3Flag);
                Program.PrintVar(nameof(immediate), immediate);
                Program.PrintVar(nameof(arg3), arg3);*/

                // three arg instructions
                switch(opcode) {
                    case Opcode.LDR:
                        registers[op1] = ReadMemory((uint)(arg2 + arg3v.Int)).Uint;
                        break;
                    case Opcode.STR:
                        replacedignMemory((uint)(arg2 + arg3v.Int), arg1);
                        break;
                    case Opcode.LDRB:
                        registers[op1] = ReadMemoryByte((uint)(arg2 + arg3v.Int));
                        break;
                    case Opcode.STRB:
                        replacedignMemoryByte((uint)(arg2 + arg3v.Int), (byte)arg1);
                        break;
                    case Opcode.SHRS:
                        registers[op1] = (uint)((int)arg2 >> (int)arg3);
                        break;
                    case Opcode.SHRU:
                        registers[op1] = arg2 >> (int)arg3;
                        break;
                    case Opcode.SHL:
                        registers[op1] = arg2 << (int)arg3;
                        break;
                    case Opcode.AND:
                        registers[op1] = arg2 & arg3;
                        break;
                    case Opcode.OR:
                        registers[op1] = arg2 | arg3;
                        break;
                    case Opcode.XOR:
                        registers[op1] = arg2 ^ arg3;
                        break;
                    case Opcode.NOT:
                        registers[op1] = ~arg2;
                        break;
                    case Opcode.ADD:
                        registers[op1] = arg2 + arg3;
                        break;
                    case Opcode.SUB:
                        registers[op1] = arg2 - arg3;
                        break;
                    case Opcode.MUL:
                        registers[op1] = arg2 * arg3;
                        break;
                    case Opcode.DIV:
                        if(arg2 == 0) {
                            status = Status.DIVISION_BY_ZERO;
                            return false;
                        }

                        registers[op1] = arg2 / arg3;
                        break;
                    case Opcode.MOD:
                        if(arg2 == 0) {
                            status = Status.DIVISION_BY_ZERO;
                            return false;
                        }

                        registers[op1] = arg2 % arg3;
                        break;
                    case Opcode.ADDF:
                        registers[op1] = new Value32 { Float = arg2v.Float + arg3v.Float }.Uint;
                        break;
                    case Opcode.SUBF:
                        registers[op1] = new Value32 { Float = arg2v.Float - arg3v.Float }.Uint;
                        break;
                    case Opcode.MULF:
                        registers[op1] = new Value32 { Float = arg2v.Float * arg3v.Float }.Uint;
                        break;
                    case Opcode.DIVF:
                        if(arg2v.Float == 0) {
                            status = Status.DIVISION_BY_ZERO;
                            return false;
                        }

                        registers[op1] = new Value32 { Float = arg2v.Float / arg3v.Float }.Uint;
                        break;
                    case Opcode.MODF:
                        if(arg2v.Float == 0) {
                            status = Status.DIVISION_BY_ZERO;
                            return false;
                        }

                        registers[op1] = new Value32 { Float = arg2v.Float % arg3v.Float }.Uint;
                        break;
                    default:
                        handledHere = false;
                        break;
                }

                if(handledHere) {
                    continue;
                }

                status = Status.MISSING_INSTRUCTION;
                return false;
            }

            if(savedStatus != Status.UNDEFINED) {
                status = savedStatus;
                return false;
            } else {
                status = Status.SUCCESS;
                return true;
            }
        }

19 View Source File : CreateRealTime3DPointCloudChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnTimerTick(object sender, EventArgs e)
        {           
            

            // Subsequent load, update point positions using a sort of brownian motion by using random
            // 

            // Access Raw 'arrays' to the inner data series. This is the fastest way to read and access data, however
            // any operations will not be thread safe, and will not trigger a redraw. This is why we invalidate below
            //
            // See also XyzDataSeries.Append, Update, Remove, Insert which are atomic operations
            // 
            // Note that the count of raw arrays may be greater than _xyzData.Count
            double[] xDataRaw = _xyzData.XValues.ToUncheckedList();
            double[] yDataRaw = _xyzData.YValues.ToUncheckedList();
            double[] zDataRaw = _xyzData.ZValues.ToUncheckedList();

            // Update the data positions simulating 3D random walk / brownian motion 
            for (int i = 0, count = _xyzData.Count; i < count; i++)
            {
                xDataRaw[i] += _random.NextDouble() - 0.5;
                yDataRaw[i] += _random.NextDouble() - 0.5;
                zDataRaw[i] += _random.NextDouble() - 0.5;
            }

            // Raise DataSeriesChanged event and trigger chart updates
            _xyzData.IsDirty = true;
            _xyzData.OnDataSeriesChanged(DataSeriesUpdate.DataChanged, DataSeriesAction.Update);            
        }

19 View Source File : AddRemoveDataSeries3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void AddSeriesButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (sciChart.RenderableSeries.Count >= MaxSeriesAmount)
            {
                return;
            }

            var renderSerias = new ScatterRenderableSeries3D();
            var xyzDataSeries3D = new XyzDataSeries3D<double>() {SeriesName = "Series " + ++_currentSeries};

            int dataPointsCount = 15;
            var random = new Random(0);

            for (int i = 0; i < dataPointsCount; i++)
            {
                double x = DataManager.Instance.GetGaussianRandomNumber(5, 1.5);
                double y = DataManager.Instance.GetGaussianRandomNumber(5, 1.5);
                double z = DataManager.Instance.GetGaussianRandomNumber(5, 1.5);

                // Scale is a multiplier used to increase/decrease ScatterRenderableSeries3D.ScatterPointSize
                float scale = (float)((random.NextDouble() + 0.5) * 3.0);

                // Color is applied to PointMetadata3D and overrides the default ScatterRenderableSeries.Stroke property
                Color? randomColor = Color.FromArgb(0xFF, (byte)random.Next(50, 255), (byte)random.Next(50, 255), (byte)random.Next(50, 255));

                // To declare scale and colour, add a VertextData clreplaced as the w (fourth) parameter. 
                // The PointMetadata3D clreplaced also has other properties defining the behaviour of the XYZ point
                xyzDataSeries3D.Append(x, y, z, new PointMetadata3D(randomColor, scale));
            }

            var randomPicker = new Random();
            int randValue = randomPicker.Next(0, 6);

            switch (randValue)
            {
                case 0:
                    renderSerias.PointMarker = new CubePointMarker3D();
                    break;
                case 1:
                    renderSerias.PointMarker = new EllipsePointMarker3D();
                    break;
                case 2:
                    renderSerias.PointMarker = new PyramidPointMarker3D();
                    break;
                case 3:
                    renderSerias.PointMarker = new QuadPointMarker3D();
                    break;
                case 4:
                    renderSerias.PointMarker = new SpherePointMarker3D();
                    break;
                case 5:
                    renderSerias.PointMarker = new TrianglePointMarker3D();
                    break;
            }

            renderSerias.DataSeries = xyzDataSeries3D;
            sciChart.RenderableSeries.Add(renderSerias);

            var index = sciChart.RenderableSeries.IndexOf(renderSerias);
            xyzDataSeries3D.SeriesName = String.Format("Series #{0}", index);

            OnPropertyChanged("CanAddSeries");
            OnPropertyChanged("CanRemoveSeries");

            sciChart.ZoomExtents();
        }

19 View Source File : ZoomHistoryMvvmViewModel.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries FillData(IUniformXyDataSeries<double> dataSeries, string name)
        {
            double randomWalk = 10.0;
            double[] yBuffer = new double[Count];

            for (int i = 0; i < Count; i++)
            {
                randomWalk += _random.NextDouble() - 0.498;
                yBuffer[i] = randomWalk;
            }

            // Buffer above and append all in one go to avoid multiple recalculations of series range
            dataSeries.Append(yBuffer);
            dataSeries.SeriesName = name;

            return dataSeries;
        }

See More Examples