C# random numbers 🎲

preview_player
Показать описание
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();
}
}
}
Рекомендации по теме
Комментарии
Автор

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

BroCodez
Автор

Super quick and simple. In my opinion, best format.

pandaonsteroids
Автор

Man even put the code in the comments. What a legend

alexanderdzhadzhev
Автор

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.

enavoid
Автор

YES, I’VE DONE IT, I’VE STOLEN CODE FOR MY OWN

lukascritical
Автор

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.

CoolRubiksCube
Автор

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

xhuntr
Автор

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?

jonathanlizarraga
Автор

Thanks mate!!! You helped me solve a gigantic doubt.🍷🗿

yurisantos
Автор

Do we only get number from random.NextDouble between 0 and 1?

prityansharma
Автор

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?

MadCaster
Автор

How can I limit the decimal places? Also your channel is very helpful Thank you.❤

pauze_play
Автор

hello thanks Bro it's really helpful for me

ZeeWolfed
Автор

bro this is really help me a lot thanks bro I'm a new subscriber to your channel bro

Joshuapaul
Автор

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

arctic
Автор

If I needed a random number that’s 4 ints long, would I just loop it until the length is <= 4?

blakeguffin
Автор

How do you make the code to print out all the randomly selected numbers instead for only

o.g.dominus
Автор

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.

DrewHelander
Автор

how would you make it read the line and save the number as an int ?

Boofedit
Автор

i wonder how can we keep making it generate random numbers indefinitely and break it xD

trifilosgr