本文整理汇总了C++中Rand类的典型用法代码示例。如果您正苦于以下问题:C++ Rand类的具体用法?C++ Rand怎么用?C++ Rand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/** Default constructor generates new Genome of randomized values. */
Genome::Genome(int i)
{
Rand r; // random number generating utility
ostringstream temp; // temp place to house the string version of the rand
// id
temp << i;
genes["id"] = temp.str();
// PERIOD
temp << r.randfloat(1.8, 2.0);
genes["period"] = temp.str();
// DESCENDING LENGTH
temp << r.randfloat(1.8, 2.0);
genes["decending_length"] = temp.str();
// EFFECTOR DELAY
temp << r.randfloat(1.8, 2.0);
genes["effector_delay"] = temp.str();
// PRC SLOPE
temp << r.randfloat(1.8, 2.0);
genes["prc_slope"] = temp.str();
genes["channel"] = "0";
genes["sample"] = "peeper.wav";
}
示例2: main
int main()
{
int i=0;
Rand * rnd = new Rand;
cout << "[*] Generating 100 seeds...\t\tseeds.txt" << endl;
ofstream fseed ("seeds.txt");
for (i=0; i<100; i++)
fseed << rnd->genSeed() << endl;
fseed.close();
cout << "[*] Generating " << LOOPCNT << " chars...\t\tchars.txt" << endl;
ofstream fchar ("chars.txt");
for (i=0; i<LOOPCNT; i++)
fchar << rnd->getChar();
fchar.close();
cout << "[*] Generating " << LOOPCNT << " letters...\tletters.txt" << endl;
ofstream fletter ("letters.txt");
for (i=0; i<LOOPCNT; i++)
fletter << rnd->getLetter();
fletter.close();
delete rnd;
cout << endl << endl << "[I] Now you can run these tools:" << endl << "[I] $> cntchar letters.txt" << endl << "[I] $> derandom chars.txt 1000" << endl << endl << "[I] Those tools are part of the jr-tools project:" << endl << "[I] $> git clone https://code.haibane.org/tools/jr-tools" << endl;
return 0;
}
示例3: time
//*************************************************************************
void BeatDetectorApp::NextFile()
{
roto = 0;
if(mTrack && mTrack->isPlaying())
{
mTrack->enablePcmBuffering(false);
mTrack->stop();
}
#ifdef WIN32
time_t now;
time(&now);
int time_int = (int)now;
#else
timeval now;
gettimeofday(&now, NULL);
int time_int = now.tv_sec;
#endif
Rand r;
r.seed(time_int);
int rand_file = r.nextInt(m_FileList.size());
path my_path = m_FileList[rand_file].path();
m_CurrentFile = my_path.string();
if(!write_frames)
{
mAudioSource = audio::load(m_CurrentFile);
mTrack = audio::Output::addTrack(mAudioSource, false);
mTrack->enablePcmBuffering(true);
mTrack->play();
}
//rot_inc = r.nextFloat(1.5f, 30.0f);
}
示例4: start
void DaemonState::start(bool forceFullScan, bool isReindex)
{
// Disable implicit flushing after a change
WorkerThread::immediateFlush(false);
// Do full scans ?
if (forceFullScan == true)
{
m_fullScan = true;
}
else
{
Rand randomStuff;
guint32 randomArray[5];
randomStuff.set_seed(randomArray[2]);
gint32 randomNum = randomStuff.get_int_range(0, 10);
if (randomNum >= 7)
{
m_fullScan = true;
}
#ifdef DEBUG
cout << "DaemonState::start: picked " << randomNum << endl;
#endif
}
m_isReindex = isReindex;
// Fire up the disk monitor thread
if (m_pDiskHandler == NULL)
{
OnDiskHandler *pDiskHandler = new OnDiskHandler();
pDiskHandler->getFileFoundSignal().connect(sigc::mem_fun(*this, &DaemonState::on_message_filefound));
m_pDiskHandler = pDiskHandler;
}
MonitorThread *pDiskMonitorThread = new MonitorThread(m_pDiskMonitor, m_pDiskHandler);
start_thread(pDiskMonitorThread, true);
for (set<PinotSettings::IndexableLocation>::const_iterator locationIter = PinotSettings::getInstance().m_indexableLocations.begin();
locationIter != PinotSettings::getInstance().m_indexableLocations.end(); ++locationIter)
{
m_crawlQueue.push(*locationIter);
}
#ifdef DEBUG
cout << "DaemonState::start: " << m_crawlQueue.size() << " locations to crawl" << endl;
#endif
if (m_fullScan == true)
{
CrawlHistory crawlHistory(PinotSettings::getInstance().getHistoryDatabaseName());
// Update all items status so that we can get rid of files from deleted sources
crawlHistory.updateItemsStatus(CrawlHistory::CRAWLING, CrawlHistory::TO_CRAWL, 0, true);
crawlHistory.updateItemsStatus(CrawlHistory::CRAWLED, CrawlHistory::TO_CRAWL, 0, true);
crawlHistory.updateItemsStatus(CrawlHistory::CRAWL_ERROR, CrawlHistory::TO_CRAWL, 0, true);
}
// Initiate crawling
start_crawling();
}
示例5: position
Particle::Particle( const Vec2f& origin, Rand& r )
: position( origin ),
lifespan( 1.0f ),
velocity( r.nextFloat( -1.0f, 1.0f ), r.nextFloat( -1.0f, 1.0f ) ),
acceleration( 0.0f, r.nextFloat( 0.01f, 0.03f ) ),
aging( r.nextFloat( ( 1.0f / 64 ), ( 1.0f / 128 ) ) ),
sizeRadius( r.nextFloat( 3.0f, 9.0f ) )
{ }
示例6: act
void RandomPolicy::act(const Observation &in, Action *out) const
{
out->v.resize(min_.size());
Rand *rand = RandGen::instance();
for (size_t ii=0; ii < min_.size(); ++ii)
(*out)[ii] = rand->getUniform(min_[ii], max_[ii]);
out->type = atExploratory;
}
示例7: Particle
Particle(vector<Tile*> *_tiles, Tile *_tile, Vec2f _pos, float _lifetime, Rand* _r)
{
tiles = _tiles;
tile = _tile;
lifetime = _lifetime;
pos = _pos;
expired = .0f;
rand = _r;
vel = Vec2f(rand->nextFloat(-PSPEED, PSPEED), rand->nextFloat(-PSPEED, PSPEED));
}
示例8: initWordVectors
void Vocabulary::initWordVectors(){
this->scoreVector = MatD::Zero(this->scoreDim, this->contextStr.size()-2);
this->scoreBias = MatD::Zero(1, this->contextStr.size()-2);
Rand rnd;
double r = 1.0/this->wordDim;
this->nounVector = MatD(this->wordDim, this->nounStr.size());
this->contextVector = MatD(this->wordDim, this->contextStr.size());
rnd.gauss(this->nounVector, r);
rnd.gauss(this->contextVector, r);
}
示例9: getWindowWidth
void CristalWaveApp::setup()
{
float sizeW = getWindowWidth() * 0.5f;
float sizeH = getWindowHeight() * 0.5f;
float x = 0.0f,
z = 0.0f,
y = 0.0f;
/////////////////////////////////////////////////
int numRows = PARAM_WAVE_NB_ROWS;
int gap = PARAM_WAVE_GAP + getWindowWidth() / 2000;
int numLines = getWindowWidth() / gap + 1;
/////////////////////////////////////////////////
mOpacity = 0.0f;
mOffsetCameratH = 60; // Global amplitude
// Init BackgroundLayer
mBackground.setup(getWindowWidth(), getWindowHeight(), mOffsetCameratH);
// Init Wave Model
mWave.setup(getWindowWidth(), getWindowHeight(), numRows, numLines, -mOffsetCameratH);
// set a random offset
Rand rnd;
rnd.seed((unsigned long)GetTickCount());
mOffsetTime = rnd.nextFloat(0.0f, 100.0f);
// Set the Shader program
mFresnelShader.load();
mpWaveShader = &mFresnelShader;
mWave.setShader(mpWaveShader);
// --------------------------------------------------------
// Set Particule manager
int nbParticule = PARAM_NB_PARTICULES;
mEmitter.radius = PARAM_EMITTER_RADIUS;
mParticuleInTheWindManager.attrPosition = Vec3f::zero();
mParticuleInTheWindManager.attrFactor = PARAM_FORCE_FACTOR;
ParticuleManager::PARTICULE_LIFE particule_life;
particule_life.minTTL = 0.5f;
particule_life.maxTTL = 3.5f;
particule_life.minTTH = 1.0f;
particule_life.minTTH = 4.0f;
mParticuleInTheWindManager.init(nbParticule, particule_life, getWindowWidth());
}
示例10: choose
int choose(Rand& rand) const {
const size_t v = rand.get(totalRatio);
for (size_t i = 0; i < TYPE_MAX; i++) {
if (v < ratio[i]) return i;
}
throw cybozu::Exception("must not reach here.");
}
示例11: sample_discrete
size_t sample_discrete(const double* cumsum, const size_t m, int level, Rand& rng)
{
size_t a = 0;
size_t b = m - 1;
size_t c;
double z = cumsum[b];
double r = rng.rand_01() * z;
// bisection search
while (level > 0){
c = (a + b) / 2;
if (r < cumsum[c]){
b = c;
} else {
a = c + 1;
}
--level;
}
// linear search
for (size_t i = a; i <= b; ++i){
if (r < cumsum[i]){
return i;
}
}
throw std::logic_error("sample_discrete reached end");
}
示例12: init
void Layer::init(Rand& rand)
{
double dev = std::max(0.3, 1.0 / m_weights.cols());
for(size_t i = 0; i < m_weights.rows(); i++)
{
vector<double>& row = m_weights[i];
for(size_t j = 0; j < m_weights.cols(); j++)
{
row[j] = dev * rand.normal();
}
}
for(size_t j = 0; j < m_weights.rows(); j++)
{
m_bias[j] = dev * rand.normal();
}
}
示例13: shuffleRows
void Matrix::shuffleRows(Rand& r, Matrix* pBuddy)
{
if(pBuddy)
{
for(size_t n = rows(); n > 0; n--)
{
size_t i = (size_t)r.next(n);
std::swap(m_data[i], m_data[n - 1]);
std::swap((*pBuddy)[i], (*pBuddy)[n - 1]);
}
}
else
{
for(size_t n = rows(); n > 0; n--)
std::swap(m_data[(size_t)r.next(n)], m_data[n - 1]);
}
}
示例14: start
void DaemonState::start(bool forceFullScan)
{
// Disable implicit flushing after a change
WorkerThread::immediateFlush(false);
// Do full scans ?
if (forceFullScan == true)
{
m_fullScan = true;
}
else
{
Rand randomStuff;
guint32 randomArray[5];
randomStuff.set_seed(randomArray[2]);
int randomNum = randomStuff.get_int_range(0, 10);
if (randomNum >= 7)
{
m_fullScan = true;
}
#ifdef DEBUG
cout << "DaemonState::start: picked " << randomNum << endl;
#endif
}
// Fire up the mail monitor thread now
m_pMailHandler = new MboxHandler();
MonitorThread *pMailMonitorThread = new MonitorThread(m_pMailMonitor, m_pMailHandler);
pMailMonitorThread->getDirectoryFoundSignal().connect(SigC::slot(*this, &DaemonState::on_message_filefound));
start_thread(pMailMonitorThread, true);
// Same for the disk monitor thread
m_pDiskHandler = new OnDiskHandler();
MonitorThread *pDiskMonitorThread = new MonitorThread(m_pDiskMonitor, m_pDiskHandler);
pDiskMonitorThread->getDirectoryFoundSignal().connect(SigC::slot(*this, &DaemonState::on_message_filefound));
start_thread(pDiskMonitorThread, true);
set<PinotSettings::IndexableLocation>::const_iterator locationIter = PinotSettings::getInstance().m_indexableLocations.begin();
if (locationIter != PinotSettings::getInstance().m_indexableLocations.end())
{
// Crawl this now
crawlLocation(locationIter->m_name, true, locationIter->m_monitor);
}
}
示例15: setRandomData
void setRandomData(AlignedArray& buf, Rand& rand)
{
size_t off = 0;
while (off < buf.size()) {
const size_t size = std::min<size_t>(buf.size() - off, 16);
rand.fill(buf.data() + off, size);
off += 512;
}
}