Program: Generate random fake news headlines


C++ program to generate random (fake) news headlines.

Bored of lockdown? Depressed by the news? Make your own.

Compiles on the Raspberry Pi, Apple Mac or Linux platform using the GNU gpp C++ compiler.


Here's the code:


#include <iostream> // Display text on the screen
#include <cstdlib>  // Random numbers
#include <unistd.h> // Uses the time to seed the random numbers (make them less prectable)

using namespace std;    // Simplifies names for screen and end-of-line

int main()
{
  // Seed the random number process - make choices more unpredictable
  srandom( time( 0 ) );

  // Arrays of data for use in creating headlines

  string possible_groups[]  =  { "Millennials", "Investors", "Labour", "Tories",
"Ministers", "Royals", "Scientists", "People",
"Students", "Teachers", "Doctors", "Police chiefs",
"Medics", "Parents", "Hard-working tax-payers", "Gen-Z" };
  const int NUM_GROUPS = 16;


  string possible_emotions[]  =  { "outraged", "amazed", "celebrating", "furious",
"jubilant", "in despair", "confused" };
  const int NUM_EMOTIONS = 7;


  string possible_times[]  =  { "yesterday", "last night", "this morning", "this week" };
  const int NUM_TIMES = 4;


  string possible_links[]  =  { "as", "after" };
  const int NUM_LINKS = 2;


  string possible_individuals[]  =  { "Ed Sheeran", "Bill Gates", "Boris", "Jeff Bezos",
"Elon Musk", "Queen", "Iggy Pop" };
  const int NUM_INDIVIDUALS = 7;


  string possible_actions[]  =  { "breaks land-speed record in shopping trolley",
"claims cheese makes you 50% more intelligent",
"TikTok video about cows goes viral",
"outlaws avocados on grounds of cyber-security",
"rules out house-price rises for the next 500 years",
"condemns use of veto by Simon Cowell",
"promises violent revolution for all under-50s",
"given ASBO for wearing large hat",
"post on Instagram causes mass hysteria",
"tweet disintegrates under weight of Jupiter",
"tweet encourages people to invest billions in plastic BitCoins",
"accuses Facebook of moving its headquarters to the moon for tax purposes" };
  const int NUM_ACTIONS = 12;


  // Determine how many headlines user wants to make
  cout << "Generate how many fake-news headlines? ";
  int howMany;
  cin >> howMany;

  cout << endl << "Generating news feed..." << endl;

  // Repeatedly choose random item from each array
  for ( int reps = 0;  reps < howMany;  reps++ )
  {
string group = possible_groups[ random() % NUM_GROUPS ];

    string emotion = possible_emotions[ random() % NUM_EMOTIONS ];

string time = possible_times[ random() % NUM_TIMES ];

string link = possible_links[ random() % NUM_LINKS ];

string individual = possible_individuals[ random() % NUM_INDIVIDUALS ];

string action = possible_actions[ random() % NUM_ACTIONS ];

// Display choices on single line as headline
    cout << group << " " << emotion << " " << time << " " << link << " " << individual << " " << action << endl;
  } // end of for loop

  // Final message after displaying all headlines
  cout << "And those are the headlines for today." << endl;
}