Advertisement
Guest User

rand_not_random

a guest
Oct 20th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. void genMapWay::saveToFile(char *fileName) const{
  2.     using std::ofstream;
  3.     std::string nameOfFile;
  4.  
  5.     if (fileName == nullptr){
  6.         char downRegSymbs[] = "qwertyuiopasdfghjklzxcvbnm";
  7.         char upRgSymbs[] = "QWERTYUIOPASDFGHJKLZXCVBNM";
  8.         char numbs[] = "1234567890";
  9.  
  10.         std::ostringstream ostr;
  11.  
  12.         ostr << m_mapHeight << 'x' << m_mapWidth << '_';
  13.         nameOfFile += ostr.str();
  14.         unsigned short randd;
  15.         srand(time(NULL));
  16.  
  17.         for (int i = 0; i < rand()%15; i++){
  18.             srand(time(0));
  19.             randd = rand()%3;
  20.             if (randd == 0)
  21.                 nameOfFile += downRegSymbs[rand()%26];
  22.             if (randd == 1)
  23.                 nameOfFile += upRgSymbs[rand()%26];
  24.             if (randd == 2)
  25.                 nameOfFile += numbs[rand()%10];
  26.         }
  27.  
  28.     } else {
  29.         nameOfFile = fileName;
  30.     }
  31.  
  32.     nameOfFile += ".txt";
  33.  
  34.     ofstream save(nameOfFile.c_str());
  35.  
  36.         for (GMW_USI i = 0; i < m_mapHeight; i++){
  37.             for (GMW_USI j = 0; j < m_mapWidth; j++){
  38.                 save << m_map[i][j] << ",";
  39.             }
  40.             save << std::endl;
  41.         }
  42.  
  43.     save.close();
  44.  
  45.     std::cout << std::endl << "Saved to file: " << nameOfFile << std::endl;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement