This is just a quickie program I made, but it brings up a good point.
wtf at the pseudo random number generator?
How could I generate a more random random number?
#include <iostream>
#include <fstream>
#include "random.h"
using namespace std;
void random_song(int);
int menu();
int main()
{
int choice = menu();
if(choice==1)
{
int length;
cout << "\nHow long should the song be (# of notes, max 100)?\n";
cin >> length;
//enum, gets a random number, assigned to a letter, makes a text file with those letters, and you're done.
random_song(length);
}
return 0;
}
int menu()
{
int c;
cout << "/nWelcome o the random song generator, what would you like to do?\n"
<< "0) Quit\n"
<< "1) Create a random song\n";
cin >> c;
if(c==1)
{
return c;
}
else
{
return 0;
}
}
void random_song(int l)
{
int note;
ofstream myFile;
myFile.open("random_song.rsong",ios::app);
for(int i=0; i<l; i++)
{
note = random_num(6);
switch (note)
{
case 0:
//Write A
myFile << 'A';
break;
case 1:
//Write B
myFile << 'B';
break;
case 2:
//write C
myFile << 'C';
break;
case 3:
//write D
myFile << 'D';
break;
case 4:
//write E
myFile << 'E';
break;
case 5:
//write F
myFile << 'F';
break;
default:
//write G
myFile << 'G';
break;
}
}
myFile.close();
}
#ifndef RANDOM_H_
#define RANDOM_H_
inline int random_num(int max_rand)
{
int rand_num;
max_rand++;
srand( (unsigned)time( NULL ) );
rand_num=rand()%max_rand;
return rand_num;
}
#endif