Quantcast
Channel: Random
Viewing all articles
Browse latest Browse all 6

Random

$
0
0
hi

here is a quick and dirty working sample for you to play with

create a new project, on the form insert a textbox, label and a button.

copy and paste following code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
// error handling required if textbox is left blank and button1 is clicked


{ int diceToRoll = System.Convert.ToInt32(textBox1.Text); if (diceToRoll == 0)// if textbox value is 0 { MessageBox.Show("Please insert a number of dice to roll "); } string[] dices = new string[diceToRoll]; Random randomizer = new Random(); for (int i = 0; i < diceToRoll; i++) { dices[i] = randomizer.Next(1, 7).ToString(); } label1.Text = string.Join(", ", dices); } } }
regards


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>