LoginSignup
5
3

More than 5 years have passed since last update.

Qtで乱数を使う

Posted at
  1. 以下をincludeする。
    • #include <QtGlobal>
    • #include <QTime>
  2. 乱数のシードを与える。
    • qsrand( QTime::currentTime().msec() );
  3. 0-255の値を得る例:
    • int random = qrand() % 256;

[環境]

% qmake --version
QMake version 3.0
Using Qt version 5.2.1 in /Users/xxxxx/Qt5.2.1/5.2.1/clang_64/lib
%
%
% clang --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix
%
%

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3