Nov 27, 2016 at 4:30am UTC
Try running this. Either by pressing
gear icon at top right of code box or using your own compiler. I kind of made this by accident.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <iostream>
#include <cstdlib>
#include <thread>
#include <chrono>
using std::this_thread::sleep_for;
using std::chrono::milliseconds;
int main()
{
std::srand(time(NULL));
int d = 1;
std::cout << "Delay between character prints (ms): " ;
while (!(std::cin >> d) || d < 1)
{
std::cin.clear();
std::cin.ignore(1000000, '\n' );
std::cout << "Invalid. Enter again: " ;
}
for (int n = 0; n != 50; n++) { std::cout << '\n' ; }
while (true )
{
std::cout << static_cast <char > (std::rand() % 300 + 1) << std::flush;
sleep_for(milliseconds(d));
}
return 0;
}
There's some issues with my code when running it with the
gear icon (
http://cpp.sh). Better running it in your own compiler.
Last edited on Nov 27, 2016 at 4:36am UTC
Nov 27, 2016 at 4:46am UTC
What is this program about?
Nov 27, 2016 at 4:49am UTC
Your program is meaningless. Just prints out random characters and that's it.
Nov 27, 2016 at 6:19am UTC
Gatenna wrote:Your program is meaningless. Just prints out random characters and that's it.
Let's keep our manners, now.
My program generates a pseudo-random number 1 through 300 and converts it to
char . As you know
integars can be converted to
char based on the
ASCII table.
I would use the
<random> library and use
random_device but it won't generate truly random numbers on all compilers.
Eg. MinGW GCC.
Last edited on Nov 27, 2016 at 6:25am UTC
Nov 27, 2016 at 6:53am UTC
@Gatenna please do not plagerise another person's code. That code which prints the shape of India is old.
Nov 28, 2016 at 7:02am UTC
shadder wrote:and interesting too...
True. I still haven't figured out completely how it works. Definitely, not how it was created.
Last edited on Nov 28, 2016 at 7:03am UTC