Curso de Programação C | Como gerar números aleatórios com as funções rand e srand? | aula 103

Coupons for my Udemy courses https://wagnergaspar.com/cupons_udemy/ Welcome to lesson number 103 of our free programming course in the C language. Typing numbers on the keyboard to test our programs can be quite laborious, especially with larger vectors. A very useful function is the rand() function, which we will learn about in this lesson. This function is used to generate random values. So, when we loop to fill a vector by reading values ​​from the keyboard, we can simply generate values ​​to fill our vector, like this: for(i = 0; i less than tam; i++) vet[i] = rand(); However, when running the program a few times, you will notice that the same values ​​are always generated. Why does this happen? The truth is that it's not possible to generate completely random numbers, to generate numbers "out of thin air". We need to start from something, from some initial value. Whoever wrote this function defined some initial value that is used to generate the numbers. The same values ​​are always generated because a default value called a seed is always used. To generate a different sequence in each execution, we need to specify our seed, a value that is different in each execution of our program. A very useful value as a seed is the computer's time, which will be different in each execution of the program, even if only by milliseconds. To use the computer's time as a seed, simply use the `srand()` function once, as follows: `#include time.h` `srand(time(null));` The `srand()` function changes the default seed to the new seed received as a parameter between the parentheses. To obtain the current computer time, we need the `time.h` library. This library contains the function that will return the computer's time: `time(null)`. Code available at: https://wagnergaspar.com/

Curso de Programação C | Gerar números aleatórios com a função rand dentro de um intervalo |aula 104
▶︎

Curso de Programação C | Gerar números aleatórios com a função rand dentro de um intervalo |aula 104

PONTEIROS EM C: SE NÃO APRENDER COM ESSE VÍDEO, ESQUECE!
▶︎

PONTEIROS EM C: SE NÃO APRENDER COM ESSE VÍDEO, ESQUECE!

TDS4223 SECTION D1011 Group 6 Warehouse Inventory System (Data Structure and Algorithm)
▶︎

TDS4223 SECTION D1011 Group 6 Warehouse Inventory System (Data Structure and Algorithm)

Curso de Programação C | O que são FUNÇÕES  e  PROCEDIMENTOS? | aula 145
▶︎

Curso de Programação C | O que são FUNÇÕES e PROCEDIMENTOS? | aula 145

Linguagem C - Aula 9.1 - Aprenda a criar e usar Funções e Procedimentos em C (2022)
▶︎

Linguagem C - Aula 9.1 - Aprenda a criar e usar Funções e Procedimentos em C (2022)

As decisões por trás de um projeto back-end real
▶︎

As decisões por trás de um projeto back-end real

Curso de Programação C | Algoritmo de ordenação Selection Sort (Ordenação por Seleção) | aula 332
▶︎

Curso de Programação C | Algoritmo de ordenação Selection Sort (Ordenação por Seleção) | aula 332

C - 50 Years of Power: Monitoring GPU, CPU, and Memory with 16KB of RAM!
▶︎

C - 50 Years of Power: Monitoring GPU, CPU, and Memory with 16KB of RAM!

Generating Random Numbers in C++. Comparing rand and srand with the new random library.
▶︎

Generating Random Numbers in C++. Comparing rand and srand with the new random library.

Linguagem C - Aula 6.2 - Strings: trabalhando com dados de texto em C (2022)
▶︎

Linguagem C - Aula 6.2 - Strings: trabalhando com dados de texto em C (2022)

Kolumbien – Portugal Highlights | Gruppe K, FIFA WM 2026 | sportstudio
▶︎

Kolumbien – Portugal Highlights | Gruppe K, FIFA WM 2026 | sportstudio

Números aleatórios em C
▶︎

Números aleatórios em C

The Strange Math That Predicts (Almost) Anything
▶︎

The Strange Math That Predicts (Almost) Anything

Creator of C++: Bell Labs, Negative Overhead Abstraction, Mistakes | Bjarne Stroustrup
▶︎

Creator of C++: Bell Labs, Negative Overhead Abstraction, Mistakes | Bjarne Stroustrup

Linguagem C - Aula 6.1 - Domine vetores (arrays) em linguagem C (2022)
▶︎

Linguagem C - Aula 6.1 - Domine vetores (arrays) em linguagem C (2022)

Linked List in C: REALLY LEARN in 20 Minutes!
▶︎

Linked List in C: REALLY LEARN in 20 Minutes!

Revisão de algoritmos e linguagem C (Aula Completa)
▶︎

Revisão de algoritmos e linguagem C (Aula Completa)

Billionaire's WARNING: I'm SELLING. The Crash Is Already Here!
▶︎

Billionaire's WARNING: I'm SELLING. The Crash Is Already Here!

Panama – England Highlights | Gruppe L, FIFA WM 2026 | sportstudio
▶︎

Panama – England Highlights | Gruppe L, FIFA WM 2026 | sportstudio

Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
▶︎

Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones