Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9134869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:44:26+00:00 2026-06-17T08:44:26+00:00

im totally stuck here on creating a random number. Ideally not the same number

  • 0

im totally stuck here on creating a random number. Ideally not the same number twice as its a customer number.

I then need to display it in my tb_id (textbox) and write the line into a customer file.

Any help here would be great.

private void button1_Click(object sender, EventArgs e)
{    
    **var rng = new Random();**
    // Here I need to write the random number (it's a customer number) to the tb_id text box. so I'm able to write it to their customer file afterwards.

    try
    {
        string fileName = string.Format(tb_surname.Text);

        if (tb_firstname.Text == "" || fileName == "" || tb_postcode.Text == "")
        {
            MessageBox.Show("Missing values from textboxes!");
        }
        else if (File.Exists(fileName + "Text"))
        {
            if (MessageBox.Show("Warning: There is already a file with the surname you enter already on the system. Contents will be replaced - do you want to continue?", "File Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                 MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.Yes)
            {
                //write lines of text to file
                StreamWriter outputStream = File.CreateText(fileName + ".Txt");
                outputStream.WriteLine(tb_firstname.Text);
                outputStream.WriteLine(tb_surname.Text);
                outputStream.WriteLine(tb_surname.Text);
                **outputStream.WriteLine(tb_id.Text);**
                outputStream.Close();
                MessageBox.Show("Text saved to file successfully!");
                this.Close();
            }
        }
    }
    // ...
}

part 2

       // creating a random number here for the customer id
        Guid g = Guid.NewGuid();
        tb_id.Text = g.ToString();

to write Guid number to a text file.

        outputStream.WriteLine(tb_id.Text);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:44:27+00:00Added an answer on June 17, 2026 at 8:44 am

    I would not recomend using the random number if you want to get it unique for users there is a high probability of getting different users with same number.

    guid is probably better idea

      Guid g = Guid.NewGuid();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a Regex javascript split, but I'm totally stuck. Here's my
I am totally stuck here and found tens of samples on posting to get
I'm sure this is easy, but I'm totally stuck here. I'm using sf2 to
I'm totally stuck on creating a user defined function in Excel VBA for the
I've read as much as I can, but totally stuck here (had it working
I am totally stuck here and found tens of samples on posting to get
I totally stuck here. I finished my app and when trying to build with
I'm totally stuck on what is going on when I try to run the
I'm totally stuck and have no idea how to go about solving this. Let's
Totally confused here. I have a PARENT UIViewController that needs to pass an NSMutableArray

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.