Created
May 10, 2021 10:18
-
-
Save kaityo256/ddcada7f2a18a60b4d9483d5c056a273 to your computer and use it in GitHub Desktop.
C++ to Python Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <fstream> | |
#include <random> | |
#include <string> | |
#include <vector> | |
const int L = 64; | |
const int N = L * L; | |
std::vector<int> spins(L *L); | |
void init() { | |
std::mt19937 mt; | |
std::uniform_int_distribution<> ud(0, 1); | |
for (int i = 0; i < N; i++) { | |
int r = ud(mt); | |
spins[i] = r * 2 - 1; | |
} | |
} | |
void save_data(const std::string filename) { | |
std::ofstream ofs(filename, std::ios::binary); | |
ofs.write((char *)spins.data(), spins.size() * sizeof(int)); | |
} | |
int main() { | |
init(); | |
save_data("test.dat"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
以下を実行すると
test.pngができます。