jeudi 28 septembre 2017

Why is my return values keep giving me 0 on a random congruential number generator program?

So I'm creating a simple random congruential number generator. It's the first time I'm using windows forms and for some reason the results keep giving me 0. Can someone tell me what's going on?

What my program is doing is the user adds the seed the a, c, mod value, and how many times it wants to iterate random numbers. But when I click generate it just gives me 0's in each new line depending how much I want it to iterate. At least I know the iteration is correct.

namespace Metodos
{
    public partial class Mixto : Form
    {
        public Mixto()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void bttnGen_Click(object sender, EventArgs e)
        {
            int seed, a, c, mod, it, numrand, residuo;
            float division;

            seed = Convert.ToInt32(txtSeed.Text);
            a = Convert.ToInt32(txtA.Text);
            c = Convert.ToInt32(txtC.Text);
            mod = Convert.ToInt32(txtMod.Text);
            it = Convert.ToInt32(txtIt.Text);




            for (int i = 1; i <= it; i++)
            {
                string newLine = Environment.NewLine;

                numrand = seed * a + c;

                residuo = numrand % mod;

                division = residuo / mod;

                residuo = seed;

                results.Text = results.Text + newLine + division.ToString();

            }







        }

        private void results_Click(object sender, EventArgs e)
        {

        }

        private void bttnClear_Click(object sender, EventArgs e)
        {

            results.Text = "";

        }
    }
}




Aucun commentaire:

Enregistrer un commentaire