D E A D L Y 13 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# Quote Share this post Link to post Share on other sites
chrisFTP 144 Random rnd = new Random(); int x = rnd.Next(0, 9); ... Quote Share this post Link to post Share on other sites
D E A D L Y 13 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 Quote Share this post Link to post Share on other sites
300Thousand 102 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 Quote Share this post Link to post Share on other sites
D E A D L Y 13 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 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 Quote Share this post Link to post Share on other sites
300Thousand 102 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 Quote Share this post Link to post Share on other sites
D E A D L Y 13 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 = 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 } Quote Share this post Link to post Share on other sites
300Thousand 102 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 = 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 Quote Share this post Link to post Share on other sites
D E A D L Y 13 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 = 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 I dont think this will work, because it needs to be exactly this format: 6006491266305597 < Exact same then next 3 has to be randon, then the :pin has to be different numbers. Quote Share this post Link to post Share on other sites
300Thousand 102 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 = 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 I dont think this will work, because it needs to be exactly this format: 6006491266305597 < Exact same then next 3 has to be randon, then the :pin has to be different numbers. okay then do it like my first imgur pic. the fixed numbers you will save in a segment like s1=6006 s2=4912 and so on then print them and after that you can use the random command in a for loop and print them in every loop and if the loop printed the 3 number print a ":" and that should be it ^^ you can also use the same code like me in C# i guess Quote Share this post Link to post Share on other sites
D E A D L Y 13 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 I dont think this will work, because it needs to be exactly this format: 6006491266305597 < Exact same then next 3 has to be randon, then the :pin has to be different numbers. okay then do it like my first imgur pic. the fixed numbers you will save in a segment like s1=6006 s2=4912 and so on then print them and after that you can use the random command in a for loop and print them in every loop and if the loop printed the 3 number print a ":" and that should be it ^^ you can also use the same code like me in C# i guess Not sure how c works but its somewhat the same at C#, but I did exactly what ur code was then edit a bit, I got it working what I liked, but its not doing more then 1 number, any ideas? Quote Share this post Link to post Share on other sites
300Thousand 102 I dont think this will work, because it needs to be exactly this format: 6006491266305597 < Exact same then next 3 has to be randon, then the :pin has to be different numbers. okay then do it like my first imgur pic. the fixed numbers you will save in a segment like s1=6006 s2=4912 and so on then print them and after that you can use the random command in a for loop and print them in every loop and if the loop printed the 3 number print a ":" and that should be it ^^ you can also use the same code like me in C# i guess Not sure how c works but its somewhat the same at C#, but I did exactly what ur code was then edit a bit, I got it working what I liked, but its not doing more then 1 number, any ideas? https://imgur.com/a/1g2RU2k you could also to another function with the whole code and call it in the main function but i was too lazy for that :D you first give a number how much keys you want generated and then the whole generating process you put that in a for loop so it repeats int o is the same as int i but you cant use int i on the first for loop so i needed to make another one. but there are probably much easier ways to do that i think did your teacher or professor not give you tips or something? ^^ because our professor wrote a programm, talked about it and then we need to do the same program but with slightly difference so we dont copy his code scanf is for input so the program waits for a value to proceed the program and in scanf its &codes because we need to give codes the address of the value from 5(on my screenshot) we cannot just give the value to codes Quote Share this post Link to post Share on other sites
Hawk 207 ints are numbers, like what you put into calculators if you want to print a big number, you will have to make strings string result = ""; Random rnd = new Random(); for (int i = 0; i < 5; i++) { result += rnd.Next(0, 9).toString(); } Console.writeline(result); Quote Share this post Link to post Share on other sites
D E A D L Y 13 okay then do it like my first imgur pic. the fixed numbers you will save in a segment like s1=6006 s2=4912 and so on then print them and after that you can use the random command in a for loop and print them in every loop and if the loop printed the 3 number print a ":" and that should be it ^^ you can also use the same code like me in C# i guess Not sure how c works but its somewhat the same at C#, but I did exactly what ur code was then edit a bit, I got it working what I liked, but its not doing more then 1 number, any ideas? https://imgur.com/a/1g2RU2k you could also to another function with the whole code and call it in the main function but i was too lazy for that :D you first give a number how much keys you want generated and then the whole generating process you put that in a for loop so it repeats int o is the same as int i but you cant use int i on the first for loop so i needed to make another one. but there are probably much easier ways to do that i think did your teacher or professor not give you tips or something? ^^ because our professor wrote a programm, talked about it and then we need to do the same program but with slightly difference so we dont copy his code scanf is for input so the program waits for a value to proceed the program and in scanf its &codes because we need to give codes the address of the value from 5(on my screenshot) we cannot just give the value to codes hmm I see, yeah well this is my "first" assignment I guess is what you can call it, he basically did 20 mins of talking about the language, then said here try it and its due by friday. He said he "wanted" to know how far or how much we know about coding, which would of been fine if its something I know, which all languages are somewhat similar but kinda different. The way you put it makes it more simple, ima take a look and retry, ill let you know how it goes. EDIT: I freaking did it, I love you all so much, I did do it a little different but it help me learn some knowledge, its amazing the community. @atiufi you're truly amazing. 1 Quote Share this post Link to post Share on other sites