Bad Luck Random Number Generator
I'm trying to generate a random int that is either 0 or 1 in C++. Right now, I receive a 0 every time I run this code, and I'm not sure why. What's the problem here? #include <ctime> #include <cstdlib> srand(time(0)); int randomval = rand() % 2; cout << randomval << endl; 8 Answers It is called bad luck. Try it again.
A Stack Overflow screenshot shows a question about a C++ program that keeps generating 0 instead of randomly producing 0 or 1. The punchline answer says, “It is called bad luck. Try it again,” humorously treating a programming issue as mere bad luck. EN: A Stack Overflow screenshot shows a question about a C++ program that keeps generating 0 instead of randomly producing 0 or 1. The punchline answer says, “It is called bad luck. Try it again,” humorously treating a programming issue as mere bad luck.
computer code / компьютерный кодStack Overflow webpage / страница Stack Overflowprogramming question / вопрос по программированиюC++ code / код C++code block / блок кодаanswer section / раздел ответовupvote arrows / стрелки голосованияgreen check mark / зелёная галочкаtext labels / текстовые подписи
- @ithueti / 2334 2020-04-27
- Template
- Stack Overflow screenshot
- Type
- image
- Size
- 763×594 · 43.0 KiB
- Mood
- sarcastic
- Language
- en
- Added