本文整理汇总了C++中Rand::getNum方法的典型用法代码示例。如果您正苦于以下问题:C++ Rand::getNum方法的具体用法?C++ Rand::getNum怎么用?C++ Rand::getNum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rand
的用法示例。
在下文中一共展示了Rand::getNum方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: seek_test
int CFileOp::seek_test(Rand &r, bool quiet, Sync &s)
{
int seek_tickets[SeekProcCount + Seeks];
int next;
for(next = 0; next < Seeks; next++)
{
seek_tickets[next] = r.getNum();
if(seek_tickets[next] < 0)
seek_tickets[next] = abs(seek_tickets[next]);
if(seek_tickets[next] % UpdateSeek == 0)
seek_tickets[next] = -seek_tickets[next];
}
for( ; next < (Seeks + SeekProcCount); next++)
seek_tickets[next] = END_SEEK_PROCESS;
if(reopen(false))
return 1;
go(NULL, SeekProcCount);
sleep(3);
if(s.decrement_and_wait(Lseek))
return 1;
if(!quiet) fprintf(stderr, "start 'em...");
if(Write(seek_tickets, sizeof(seek_tickets), 0) != int(sizeof(seek_tickets)) )
{
fprintf(stderr, "Can't write tickets.\n");
return 1;
}
Close();
for (next = 0; next < SeekProcCount; next++)
{ /* for each child */
struct report_s seeker_report;
int rc;
if((rc = Read(&seeker_report, sizeof(seeker_report), 0))
!= sizeof(seeker_report))
{
fprintf(stderr, "Can't read from pipe, expected %d, got %d.\n"
, int(sizeof(seeker_report)), rc);
return 1;
}
/*
* each child writes back its CPU, start & end times. The elapsed time
* to do all the seeks is the time the first child started until the
* time the last child stopped
*/
m_timer.add_delta_report(seeker_report, Lseek);
if(!quiet) fprintf(stderr, "done...");
} /* for each child */
if(!quiet) fprintf(stderr, "\n");
return 0;
}
示例2: random_sort
void COpenTest::random_sort(Rand &r)
{
for(int i = 0; i < m_number; i++)
{
char *tmp = m_file_names[i];
int newind = r.getNum() % m_number;
m_file_names[i] = m_file_names[newind];
m_file_names[newind] = tmp;
if(m_dirIndex)
{
int tmpInd = m_dirIndex[i];
m_dirIndex[i] = m_dirIndex[newind];
m_dirIndex[newind] = tmpInd;
}
if(*m_exit) return;
}
}
示例3: make_names
void COpenTest::make_names(Rand &r, bool do_random)
{
delete m_file_name_buf;
delete m_file_names;
int names_per_directory = m_number / m_number_directories;
int names_in_dir = 0;
int directory_num = 0;
if(!m_dirIndex && m_sync)
m_dirIndex = new int[m_number];
if(m_number_directories == 1)
{
m_file_name_buf = new char[(MaxNameLen + 1) * m_number];
}
else
{
m_file_name_buf = new char[(MaxNameLen + 1 + 6) * m_number];
}
m_file_names = new PCHAR[m_number];
PCHAR buf = m_file_name_buf;
int num_rand_chars = strlen(rand_chars);
for(int i = 0; i < m_number; i++)
{
if(*m_exit)
{
delete m_file_names;
m_file_names = NULL;
return;
}
char rand_buf[RandExtraLen + 1];
int len = r.getNum() % (RandExtraLen + 1);
int j;
for(j = 0; j < len; j++)
{
rand_buf[j] = rand_chars[r.getNum() % num_rand_chars];
}
rand_buf[j] = '\0';
m_file_names[i] = buf;
if(m_number_directories != 1)
{
sprintf(buf, "%05d/", directory_num);
buf += strlen(buf);
}
if(m_sync)
m_dirIndex[i] = directory_num;
names_in_dir++;
if(names_in_dir > names_per_directory)
{
names_in_dir = 0;
directory_num++;
}
if(do_random)
{
sprintf(buf, "%s%010x", rand_buf, i);
}
else
{
sprintf(buf, "%010x%s", i, rand_buf);
}
buf += strlen(buf) + 1;
}
}