简体   繁体   中英

VB.net C# number generator

I am trying to make a generator that has 4 constant numbers like this:

5395-5958-2009-3888 543:8933
5395-5958-2009-3888 456:3834
5395-5958-2009-3888 323:3874

Basically think of a gift card, the pin changes. I have no idea where to start but it's for my college class.

Ive tried

Random rnd = new Random();

int x = rnd.Next(0, 9);

but then the 4 constant numbers wont stay the same 1

Try following :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;

namespace ConsoleApplication108
{
    class Program
    {

        static void Main(string[] args)
        {
            Random rand = new Random();
            int[] numbers = new int[4];
            for (int i = 0; i < 4; i++)
            {
                numbers[i] = rand.Next(1000, 10000);
            }

            string prefix = string.Join("-", numbers);

            for(int i = 0; i < 100; i++)
            {
                int threeDigits = rand.Next(100, 1000);
                int lastNumber = rand.Next(1000, 10000);

                Console.WriteLine("{0}{1}:{2}", prefix,threeDigits, lastNumber);

            }


            Console.ReadLine();

        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM