Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



 3029

Could anyone help me? Trying to code a number generator...

by D E A D L Y - 09 April, 2019 - 02:17 PM
This post is by a banned member (D E A D L Y) - Unhide
181
Posts
70
Threads
5 Years of service
#1
So basically im in college and my professor is making us code a number generator in VB with C# for our first assignment...
Well basically im not use to VB or C#, i do java.

Basically he wants a set of numbers then some that change so for example
6006-5000-3000-2000-1020:1900
6006-5000-3000-2000-9033:1930
6006-5000-3000-2000-9033:1988
etc

Its basic but no idea what im doing with C#
I love people :)
This post is by a banned member (chrisFTP) - Unhide
This post is by a banned member (D E A D L Y) - Unhide
181
Posts
70
Threads
5 Years of service
#3
(09 April, 2019 - 02:19 PM)chrisFTP Wrote: Show More
Random rnd = new Random();

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

...

I already tried that, but its not gonna keep the same numbers unless im doing it wrong, I even tried basically making 12 of them numbers a constant, but still changes up
I love people :)
This post is by a banned member (Itamai) - Unhide
This post is by a banned member (D E A D L Y) - Unhide
181
Posts
70
Threads
5 Years of service
#5
(This post was last modified: 09 April, 2019 - 04:12 PM by D E A D L Y.)
(09 April, 2019 - 02:34 PM)atiufi Wrote: Show More
(09 April, 2019 - 02:29 PM)Dragonslayer3242 Wrote: Show More
(09 April, 2019 - 02:19 PM)chrisFTP Wrote: Show More
Random rnd = new Random();

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

...

I already tried that, but its not gonna keep the same numbers unless im doing it wrong, I even tried basically making 12 of them numbers a constant, but still changes up

if i understand it correctly the first 4 numberrows should stay the same? you need to modify that code that it generates random numbers after the 4 number rows because with that code everything is generated random.

i would do a for-loop and start the randomizer after the 12 numbers

Yeah u read it right, so I kinda tried that but seems like im not sure how to loop or anything correctly, this is what I got so far but nothing stays the same just random stuff and no :3838 or anything like that with pin
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.IO;

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();

       }
   }
}

Obviously it wont loop since I have no loop atm
I love people :)
This post is by a banned member (Itamai) - Unhide
This post is by a banned member (D E A D L Y) - Unhide
181
Posts
70
Threads
5 Years of service
#7
(This post was last modified: 09 April, 2019 - 05:50 PM by D E A D L Y.)
(09 April, 2019 - 04:42 PM)atiufi Wrote: Show More
here i made a picture from my code that i did just now i did not know the code command to paste it in the post thats why i post a imgur link and its on C because i did not learn C# but maybe it will help you

https://imgur.com/a/QHh7WEq
the random command works different on C then on C# if i use the rand command it generates a random number from the int value thats why i wrote rand()%10 so it only generates 0-9
the first 3  segements i just printed because they are fixed anyway and the for-loop is for how much random numbers you need and if-statement is if the forth number is generated print a ":"
and the first command after int main is just because if i start the program it has a fixed seed that means the random generated numbers are always the same if i dont change the seed thats the command for it.
sry my english typing is so bad hopefully you understood it a little more with my C code
maybe you can adapt this to C#

and that was also training for me never used the random command :D
Thank you, ill take a look, this is what I got so far: https://imgur.com/Cx9j7Ob

Still seems I cant figure it out, basically I am pretty sure I know what to do but just dont.
for (int i = 0; i < 4; i++)
{
numbers[i] = rand.Next(1000, 10000); ( I need this to be like 1000, 2000, 3000, 4000 ) but I dont need to use rand.net but not sure what to use
}
I love people :)
This post is by a banned member (Itamai) - Unhide

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 2 Guest(s)