#include <stdio.h>
#include <stdlib.h>
const char *noun[]={"boy", "girl", "dog", "town", "car"};
const char *verb[]={"drove", "jumped", "ran", "walked", "skipped"};
const char *preposition[]={"to", "from", "under", "over", "on"};
const char *article[]={"the", "a", "one", "some", "any"};
char sentence[50];
int main(void)
{
strcat(sentence, *(article+(rand() %5)));
strcat(sentence, " ");
strcat(sentence, *(noun+(rand() %5)));
strcat(sentence, " ");
strcat(sentence, *(verb+(rand() %5)));
strcat(sentence, " ");
strcat(sentence, *(preposition+(rand() %5)));
strcat(sentence, " ");
strcat(sentence, *(article+(rand() %5)));
strcat(sentence, " ");
strcat(sentence, *(noun+(rand() %5)));
printf("%s",sentence);
getch();
return 0;
}
No.
Srand (seed random ) is used to seed random numbers and is used before calling the rand() or the random number generator. Seeding random numbers ensures that each time the code is executed the number generated is completely random. srand requires one parameter. For most cases it is sufficient to make this parameter time(NULL) [remember to include time.h] as this will seed a new bunch of random number every second
Use the C++ getline() function from the standard library.
Random numbers can be generated by a pseudo-random number generator. As of C++11, the standard library provides several generators in the <random> header. The following demonstrates how to simulate 10 throws of a die. #include <random> #include <iostream> int main (void) { std::default_random_engine gen; std::uniform_int_distribution<> dist {1, 6}; // range of distribution [1:6] for (int n=0; n<10; ++n) std::cout << dist(gen) << ' '; std::cout << '\n'; } Example output: 1 1 6 5 2 2 5 5 6 2
This program generates so called pseudo random numbers, and it used srand() function to connect the seed for the random number generator to the current. Which makes it less predictable but cannot claimed as a real random number generator.#include #include #include int main(){srand((unsigned) time(NULL));std::cout
Random example, function with two parameters: int main (int argc, char **argv) {...}
#include<iostream> #include<chrono> #include<random> #include<vector> int main() { std::vector<int> Array; unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); std::default_random_engine generator (seed); std::uniform_real_distribution<int> distribution (0,100); for (size_t index=0; index<10; ++index) Array.push_back (distribution (generator)); }
You can use rand(). Make sure that you use srand()to generate the seed for rand() (if you do not, you get so called pseudo random numbers).
b+b+b+c+c+c+c =3b+4c
c + c + 2c + c + c = 6c
b + b + b + c + c + c + c = 3b + 4c
4c