This post is by a banned member (D E A D L Y) - Unhide
OP 09 April, 2019 - 02:17 PM
Reply
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
09 April, 2019 - 02:19 PM
(This post was last modified: 09 April, 2019 - 02:20 PM by chrisFTP.)
Reply
Random rnd = new Random();
int x = rnd.Next(0, 9);
...
This post is by a banned member (D E A D L Y) - Unhide
OP 09 April, 2019 - 02:29 PM
Reply
(09 April, 2019 - 02:19 PM)chrisFTP Wrote: Show MoreRandom 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
09 April, 2019 - 02:34 PM
(This post was last modified: 09 April, 2019 - 02:36 PM by Itamai.)
Reply
(09 April, 2019 - 02:29 PM)Dragonslayer3242 Wrote: Show More (09 April, 2019 - 02:19 PM)chrisFTP Wrote: Show MoreRandom 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
This post is by a banned member (D E A D L Y) - Unhide
OP 09 April, 2019 - 03:43 PM
(This post was last modified: 09 April, 2019 - 04:12 PM by D E A D L Y.)
Reply
(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 MoreRandom 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
09 April, 2019 - 04:42 PM
(This post was last modified: 09 April, 2019 - 04:43 PM by Itamai.)
Reply
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
This post is by a banned member (D E A D L Y) - Unhide
OP 09 April, 2019 - 05:32 PM
(This post was last modified: 09 April, 2019 - 05:50 PM by D E A D L Y.)
Reply
(09 April, 2019 - 04:42 PM)atiufi Wrote: Show Morehere 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
09 April, 2019 - 06:21 PM
Reply
(09 April, 2019 - 05:32 PM)Dragonslayer3242 Wrote: Show More (09 April, 2019 - 04:42 PM)atiufi Wrote: Show Morehere 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
}
another imgur link
the site blocks my for loops because it thinks i try sql injection xD
https://imgur.com/a/IsVemLo
make a new int and increase it with thousand because you rand.next command will input a number from 1000 to 10000 so it can also be 1232 for example
|