I am considering a Qt-specific C ++ solution for a typical producer / consumer problem. Here is the code for the manufacturer:
class Producer : public QThread { public: void run() { qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); for (int i = 0; i < DataSize; ++i) { freeBytes.acquire(); // (1) buffer[i % BufferSize] = "ACGT"[(int)qrand() % 4]; // (2) usedBytes.release(); } } };
I cannot understand the second line in the loop for, namely. "ACGT"[*]. What is he doing exactly? Is this Qt specific or is it a C ++ syntax that I don't know about?
for
"ACGT"[*]
PS: Full source code here
It generates a random characteristic from: A, C, G, T.
Literal "ACGT"is an array of type char const [5], then it [(int)qrand() % 4]is a random index ranging from 0 to 3, including.
"ACGT"
char const [5]
[(int)qrand() % 4]
"ACGT" [*] . ?
qrand() % 4 - 0 3. "ACGT ". , A, C, G T.
qrand() % 4
"ACGT
Source: https://habr.com/ru/post/1540330/More articles:Предварительная декларация SBCL: возможно? - sbclCordoba 3.4 FileReader not working (no onloadend) - javascriptQt application - node.js server communication - node.jsOrchard 1.8 Getting 404 Not Found Error - Deploys Via Web Matrix - webmatrixEclipse gives error when adding MySql jdbc driver - eclipseSubmit an email order from a non-Magento 1.8 administrator - magentoDesign Pattern for Cumulative Disorders - javahow to enable h264 in peerconnection? - firefoxSpark's HBase entry: an existential type puzzle - scalaScipy Cookbook RANSAC implementation mismatch - pythonAll Articles