C#, cálculo numérico: método de cálculo y programa fuente de Ranfib

1 formato de texto

usando Sistema;

namespace Legalsoft.Truffer
{     /// <summary>     /// Implementa el generador sustractivo de Knuth usando solo operaciones flotantes. Consulte     el texto /// para conocer las precauciones.     /// </summary>     clase pública Ranfib     {         doble privado[] dtab { get; colocar; } = nuevo doble[55];         doble dd privado {obtener; colocar; }         privado int inext { get; colocar; }         privado int inextp { get; colocar; }









        Ranfib pública (ulong j)
        {             this.inext = 0;             this.inextp = 31;             Ranq1 inicio = nuevo Ranq1(j);             for (int k = 0; k < 55; k++)             {                 dtab[k] = init.doub();             }         }







        duda doble pública()
        {             if (++inext == 55)             {                 inext = 0;             }             if (++inextp == 55)             {                 inextp = 0;             }             dd = dtab[inext] - dtab[inextp];             si (dd < 0)             {                 dd += 1,0;             }             retorno (dtab[inext] = dd);         }














        /// <summary>
        /// Devuelve un entero aleatorio de 32 bits. 
        /// Recomendado sólo para fines de prueba.
        /// </summary>
        /// <returns></returns>
        public uint int32()
        {             return (uint)(doub() * 4294967295.0);         } }     }




 

2 formato de código

using System;

namespace Legalsoft.Truffer
{
    /// <summary>
    /// Implements Knuth's subtractive generator using only floating operations. See
    /// text for cautions.
    /// </summary>
    public class Ranfib
    {
        private double[] dtab { get; set; } = new double[55];
        private double dd { get; set; }
        private int inext { get; set; }
        private int inextp { get; set; }

        public Ranfib(ulong j)
        {
            this.inext = 0;
            this.inextp = 31;
            Ranq1 init = new Ranq1(j);
            for (int k = 0; k < 55; k++)
            {
                dtab[k] = init.doub();
            }
        }

        public double doub()
        {
            if (++inext == 55)
            {
                inext = 0;
            }
            if (++inextp == 55)
            {
                inextp = 0;
            }
            dd = dtab[inext] - dtab[inextp];
            if (dd < 0)
            {
                dd += 1.0;
            }
            return (dtab[inext] = dd);
        }

        /// <summary>
        /// Returns random 32-bit integer. 
        /// Recommended only for testing purposes.
        /// </summary>
        /// <returns></returns>
        public uint int32()
        {
            return (uint)(doub() * 4294967295.0);
        }
    }
}

Supongo que te gusta

Origin blog.csdn.net/beijinghorn/article/details/133231789
Recomendado
Clasificación