Тёмный

C# random numbers 🎲 

Bro Code
Подписаться 2 млн
Просмотров 66 тыс.
50% 1

C# generate random numbers tutorial example explained
#C# #random #numbers
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();
}
}
}

Наука

Опубликовано:

 

2 июл 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 59   
@BroCodez
@BroCodez 3 года назад
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(); } } }
@alexanderdzhadzhev2322
@alexanderdzhadzhev2322 2 года назад
Man even put the code in the comments. What a legend
@pandaonsteroids5154
@pandaonsteroids5154 2 года назад
Super quick and simple. In my opinion, best format.
@spartanranger
@spartanranger 2 года назад
Thanks for the video Bro
@lukascritical
@lukascritical 2 года назад
YES, I’VE DONE IT, I’VE STOLEN CODE FOR MY OWN
@tsukono1481
@tsukono1481 2 года назад
Good job bro! you're 10 steps closer to becoming a great programer!
@amritsahani69420
@amritsahani69420 Год назад
@@tsukono1481 lol
@yurisantos1277
@yurisantos1277 Год назад
Thanks mate!!! You helped me solve a gigantic doubt.🍷🗿
@CoolRubiksCube
@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.
@alexmadejalexmadej1615
@alexmadejalexmadej1615 Год назад
Thanks so much bro!
@enavoid
@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.
@sm0k356
@sm0k356 5 месяцев назад
To use random u need to create object first
@godistheonlyway
@godistheonlyway 5 месяцев назад
bro this is really help me a lot thanks bro I'm a new subscriber to your channel bro
@o.g.dominus
@o.g.dominus 2 года назад
How do you make the code to print out all the randomly selected numbers instead for only
@ChristopherGray00
@ChristopherGray00 2 года назад
great video
@ZeeWolfed
@ZeeWolfed Год назад
hello thanks Bro it's really helpful for me
@mrmarriedtothegame
@mrmarriedtothegame 3 дня назад
Legend
@humeyraylmaz3295
@humeyraylmaz3295 2 года назад
thank u, it helped
@editsbyjust_abs
@editsbyjust_abs Год назад
Thank u man
@Sayori251
@Sayori251 Год назад
1k likes? underrated dude.
@Mad1Caster
@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
@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
@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
@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.
@LeGoat72
@LeGoat72 Год назад
nice im the 900th like
@sandarubandara4437
@sandarubandara4437 6 месяцев назад
Thanks bro
@MonderMurshed
@MonderMurshed Год назад
THANKS
@DrewHelander
@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
@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.
@resturizkiawan8029
@resturizkiawan8029 Год назад
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
@blakeguffin886
@blakeguffin886 Год назад
If I needed a random number that’s 4 ints long, would I just loop it until the length is
@JosPlays
@JosPlays 10 месяцев назад
Or just set the random of Random.Next(1000,10000). That also does the trick.
@macsoccer2012
@macsoccer2012 2 года назад
I'm not understanding what the point of the 'new' keyword is. Anyone have an understanding?
@DailyFunnyHouse
@DailyFunnyHouse Год назад
same here, you know the reason now?
@MyReviews_karkan
@MyReviews_karkan 5 месяцев назад
Num1, num2, num3, and numnuts
@harsinghsekhon5935
@harsinghsekhon5935 Год назад
I want to get two different random numbers but by this of way generating numbers, it gives me 2 same random numbers.
@pauze_play
@pauze_play 9 месяцев назад
How can I limit the decimal places? Also your channel is very helpful Thank you.❤
@amerbegic5932
@amerbegic5932 6 месяцев назад
double num = Math.Round(random.NextDouble(), number of decimal places);
@Ilijan99
@Ilijan99 17 дней назад
double randomNumber = random.NextDouble() * 10.0; Console.WriteLine(randomNumber);
@ericmiyan3466
@ericmiyan3466 Год назад
i can't use the class Random. Even when i copy paste your code. Can anyone help?
@prityansharma
@prityansharma 4 месяца назад
Do we only get number from random.NextDouble between 0 and 1?
@Ilijan99
@Ilijan99 17 дней назад
double randomNumber = random.NextDouble() * 10.0; Console.WriteLine(randomNumber);
@arctic8137
@arctic8137 6 месяцев назад
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
@whitedinamo
@whitedinamo 2 года назад
lesson check 😇
@Boofedit
@Boofedit 2 года назад
how would you make it read the line and save the number as an int ?
@Infragion
@Infragion 2 года назад
write "Console.ReadKey();" for u can read or "Console.ReadLine();"
@Infragion
@Infragion 2 года назад
for int u can do: "int = ;"
@xhunt8r
@xhunt8r Месяц назад
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();
@yourkodi3945
@yourkodi3945 2 года назад
but the random numbers can repeat every now and again??
@kevinandris
@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.
@multishep4340
@multishep4340 Год назад
Random is an error, red lines all over my screen ahhhh
3 года назад
Thanks!
@hemanichius3941
@hemanichius3941 Год назад
babol Eze
@creativekev5215
@creativekev5215 7 месяцев назад
random comment 👍
@WickedJackThe1
@WickedJackThe1 Год назад
42
@carsonrichards4428
@carsonrichards4428 2 года назад
+
@shadowplayer11.86
@shadowplayer11.86 6 месяцев назад
7
@blubee6896
@blubee6896 5 месяцев назад
Random comment
@FukSN
@FukSN Год назад
Random vid this
Далее
C# hypotenuse calculator program 📐
2:08
Просмотров 19 тыс.
СДЕЛАЛА БРЕКЕТЫ ДОМА
01:01
Просмотров 1,3 млн
How To Predict Random Numbers Generated By A Computer
13:54
True Random Numbers - Computerphile
12:16
Просмотров 122 тыс.
C# generics ⁉️
5:33
Просмотров 70 тыс.
C# enums 🪐
7:07
Просмотров 66 тыс.
C# static 🚫
5:03
Просмотров 66 тыс.
C# interfaces 🐟
5:38
Просмотров 123 тыс.
The Algorithm Behind Spell Checkers
13:02
Просмотров 408 тыс.
Самый быстрый пылесос!
0:30
Просмотров 22 тыс.
iPhone 16 - НЕ СТОИТ ПРОПУСКАТЬ
4:50