Jonathan Crispe

Jonathan Crispe

  • NA
  • 46
  • 48.3k

Array random numbers for doubles

Oct 25 2011 7:46 PM


so far i have this: i couldn't figure out how to make an array.
Generate button, i called it BTN_generate
  public partial class Form1 : Form
  {
  Random random = new Random();
  double dtotal = 0;
  public Form1()
  {
  InitializeComponent();
 
  }

  private void BTN_generate_Click(object sender, EventArgs e)
  {
  int irandom = random.Next(0, 100);
  double drandom = random.NextDouble();

  dtotal = irandom + drandom;
  textBox1.Text = dtotal.ToString("0.00");
  }
  }

and i tried without double drandom = random.NextDouble();
  public partial class Form1 : Form
  { 
  int[] iArray = new int[20];
 
  Random rNumber = new Random(101);but my code didn't work

  private void BTN_generate_Click(object sender, EventArgs e)
  {
  for (int i = 0; i < iArray.Length; i++)
  {
  iArray[i] = rNumber.Next(101);
  }

  Console.WriteLine();
  foreach (int iValue in iArray)
  {
  textbox1.Text = iValue.ToString();
  }
  }
  }

this one is just giving me one number.

Answers (3)