using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { Random random = new Random(); int num1 = random.Next(1, 7); int num2 = random.Next(1, 7); int num3 = random.Next(1, 7); //double num = random.NextDouble(); Console.WriteLine(num1); Console.WriteLine(num2); Console.WriteLine(num3); Console.ReadKey(); } } }
@pandaonsteroids5154
2 жыл бұрын
Super quick and simple. In my opinion, best format.
@alexanderdzhadzhev2322
2 жыл бұрын
Man even put the code in the comments. What a legend
@enavoid
Жыл бұрын
I'm loving this series. I just have trouble understand what the hell the first line is. Random random = new Random(); why are there 3 randoms and why is there a "new" This tutorial is made for beginners but doesn't explain what you're doing.
@lukascritical
2 жыл бұрын
YES, I’VE DONE IT, I’VE STOLEN CODE FOR MY OWN
@tsukono1481
2 жыл бұрын
Good job bro! you're 10 steps closer to becoming a great programer!
@amritsahani69420
Жыл бұрын
@@tsukono1481 lol
@CoolRubiksCube
Жыл бұрын
This isn't working for me. Is it due to using Unity? There are no errors shown in VS Code, however in Unity it tells me that there is no definition for "Next" in "Random". Help? Edit: Solved, just use Random.Range() in Unity.
@east2381
2 ай бұрын
time to make a gambling simulator
@spartanranger
3 жыл бұрын
Thanks for the video Bro
@MyReviews_karkan
8 ай бұрын
Num1, num2, num3, and numnuts
@prityansharma
7 ай бұрын
Do we only get number from random.NextDouble between 0 and 1?
bro this is really help me a lot thanks bro I'm a new subscriber to your channel bro
@yurisantos1277
Жыл бұрын
Thanks mate!!! You helped me solve a gigantic doubt.🍷🗿
@jonathanlizarraga8446
Ай бұрын
how do i assign a name to a specific int it gives me? like is i have a range of (1, 4) and 3 gets picked, how do i make it so that triggers a specific outcome?
@xhunt8r
4 ай бұрын
You can use the "for" loop to output 3 numbers, etc.) Random rnd = new Random(); for (int i = 0; i < 3; i++) { int num = rand.Next(1, 7); Console.WriteLine(num); } Console.ReadKey();
@Sayori251
Жыл бұрын
1k likes? underrated dude.
@Mad1Caster
2 жыл бұрын
Okay but how to do this as a loop such as a turn base with a chance to hit being the 20 sided dice and an 8 side for damage. how can I get it to not continuously show the same number generated once line starts?
@fzlagges5849
2 жыл бұрын
just initialise the num within the loop i.e while(condition for number of random numbers to be generated) {num = random.Next(range);}
@Mad1Caster
2 жыл бұрын
@@fzlagges5849 I was using an IF loop for it and only called it once i.e if(rmd < 5) {...code...} when I should have had it do if(rmd = 1) {...code...} just to clarify i already set up rmd =random.Next(range); Thanks though
@fzlagges5849
2 жыл бұрын
@@Mad1Caster There is no such thing as an if loop, if block always executes only once, and what initialising num within while loop does is, it generates a new random number every time random.Next() is called and that is saved within num.
@mrmarriedtothegame
2 ай бұрын
Legend
@alexmadejalexmadej1615
2 жыл бұрын
Thanks so much bro!
@pauze_play
Жыл бұрын
How can I limit the decimal places? Also your channel is very helpful Thank you.❤
@amerbegic5932
9 ай бұрын
double num = Math.Round(random.NextDouble(), number of decimal places);
i wonder how can we keep making it generate random numbers indefinitely and break it xD
@simik4830
16 күн бұрын
comment for algorithm!
@o.g.dominus
2 жыл бұрын
How do you make the code to print out all the randomly selected numbers instead for only
@Justabss
Жыл бұрын
Thank u man
@arctic8137
9 ай бұрын
no where i put this it works. i understand it but i dont know here to put it to work. its currently in my void start
@sandarubandara4437
9 ай бұрын
Thanks bro
@blakeguffin886
2 жыл бұрын
If I needed a random number that’s 4 ints long, would I just loop it until the length is
@JosPlays
Жыл бұрын
Or just set the random of Random.Next(1000,10000). That also does the trick.
@MonderMurshed
Жыл бұрын
THANKS
@ChristopherGray00
2 жыл бұрын
great video
@DrewHelander
2 жыл бұрын
What if I want the numbers in the 1 - 6 range per se, but I dont want any of them to repeat. So out of 3 dice I want one to roll a 3, a 2 and a 6, but not a 3, a 3 and a 6. Sounds confusing but really I dont want the numbers to repeat.
@dianab4494
2 жыл бұрын
if you haven't figured it out, you might want to try a method which includes loop which generates random numbers, and then passes them if they are not the same as old ones. I can try to code it later and will comment it soon.
@nextarbrownies62
Жыл бұрын
I will use list to store the numbers. 1. generate random(0, count numbers inside list) 2. use generated number as index to get from list 3. print out the value from list, then remove it from list - repeat step 1 to 3
@humeyraylmaz3295
2 жыл бұрын
thank u, it helped
@harsinghsekhon5935
Жыл бұрын
I want to get two different random numbers but by this of way generating numbers, it gives me 2 same random numbers.
@yourkodi3945
2 жыл бұрын
but the random numbers can repeat every now and again??
@kevinandris
2 жыл бұрын
Of course, but if you have random numbers stored into an array, you can check if the current generated number is equal to any previous generated number with a for loop. Inside for loop you compare already existing number with a new number using an if statement, and if the 2 numbers are equal you can generate a new number, that replaces this duplicate number.
@whitedinamo
2 жыл бұрын
lesson check 😇
@macsoccer2012
2 жыл бұрын
I'm not understanding what the point of the 'new' keyword is. Anyone have an understanding?
@DailyFunnyHouse
2 жыл бұрын
same here, you know the reason now?
@ericmiyan3466
Жыл бұрын
i can't use the class Random. Even when i copy paste your code. Can anyone help?
@Boofedit
2 жыл бұрын
how would you make it read the line and save the number as an int ?
@Infragion
2 жыл бұрын
write "Console.ReadKey();" for u can read or "Console.ReadLine();"
@Infragion
2 жыл бұрын
for int u can do: "int = ;"
@multishep4340
Жыл бұрын
Random is an error, red lines all over my screen ahhhh
Пікірлер: 64