本文整理汇总了C++中random32函数的典型用法代码示例。如果您正苦于以下问题:C++ random32函数的具体用法?C++ random32怎么用?C++ random32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random32函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: brodge
void brodge(struct c642_pict *pict)
{
int o;
int at[2], m[2];
long d;
struct timespec ls = current_kernel_time();
c642_esqu(pict);
//°\\ 0: osc1 , 1: osc2 , 2: osc3
for(o = 0; o < 2; o++) {
d = 1L * pict->num_at * random32();
at[o] = d >> 32;
}
d = 4L * random32();
m[0] = d >> 32;
d = 4L * random32();
m[1] = d >> 32;
brodge1(pict, at, m);
pict->sig = current_kernel_time();
d = (pict->sig.tv_nsec - ls.tv_nsec);
if ( d < 0 ) {
printk("Brodge ' %lX ' taked %ld.%lds.\n", pict->sig.tv_sec, pict->sig.tv_sec - ls.tv_sec - 1, (1000000000 - d)/1000000);
} else {
printk("Brodge ' %lX ' taked %ld.%lds.\n", pict->sig.tv_sec, pict->sig.tv_sec - ls.tv_sec, d/1000000);
}
// Sig
// Export
d = a051_data_write(pict->env, pict->picture, pict->size);
printk("Brodge ' %lX ' send %ld bytes\n", 0x7F1FFFFFFF & (1L * pict->sig.tv_sec * 1000L + pict->sig.tv_nsec / 1000000L), d);
}
开发者ID:gregory-kononovitch,项目名称:f642,代码行数:35,代码来源:c642_pictu4.c
示例2:
quint64 Zobrist::random64()
{
quint64 random1 = (quint64)random32();
quint64 random2 = (quint64)random32();
quint64 random3 = (quint64)random32();
return random1 ^ (random2 << 31) ^ (random3 << 62);
}
开发者ID:Hasimir,项目名称:cutechess,代码行数:8,代码来源:zobrist.cpp
示例3: random32
end_point replication_app_client_base::get_read_address(read_semantic_t semantic, const partition_configuration& config)
{
if (semantic == read_semantic_t::ReadLastUpdate)
return config.primary;
// readsnapshot or readoutdated, using random
else
{
bool has_primary = false;
int N = static_cast<int>(config.secondaries.size());
if (config.primary != dsn::end_point::INVALID)
{
N++;
has_primary = true;
}
if (0 == N) return config.primary;
int r = random32(0, 1000) % N;
if (has_primary && r == N - 1)
return config.primary;
else
return config.secondaries[r];
}
}
开发者ID:SunnyGyb,项目名称:rDSN,代码行数:25,代码来源:replication_app_client_base.cpp
示例4: nasty_write
static ssize_t nasty_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
int rcount, ret; /* random bytes to write */
/* 0 in -> 0 out, no strings attached */
if (count == 0)
return 0;
/* end of story */
if (*ppos >= FILE_MAX_SIZE)
return -ENOSPC;
/* make sure that we write at least 1 character */
rcount = 1 + random32() % MAX_CHUNK_SIZE;
/* ... and don't cross the borders */
if (rcount > count)
rcount = count;
if (*ppos + rcount > FILE_MAX_SIZE)
rcount = FILE_MAX_SIZE - *ppos;
ret = copy_from_user(&content[*ppos], buf, rcount);
if (ret != 0) {
pr_warning("@write: copy to user failead\n");
return -EFAULT;
}
pr_debug("@write: requested %d, written %d, current pos %lld\n",
count, rcount, *ppos);
*ppos += rcount;
crt_size = max(crt_size, (int)*ppos);
return rcount;
}
开发者ID:alexandrucomanescu,项目名称:ASCPublic,代码行数:32,代码来源:nasty.c
示例5: nasty_read
static ssize_t nasty_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
int rcount, ret; /* random bytes to read */
/* end of file */
if (*ppos >= crt_size)
return 0;
/* make sure that we read at least 1 character */
rcount = 1 + random32() % MAX_CHUNK_SIZE;
/* ... and don't cross the borders */
if (rcount > count)
rcount = count;
if (*ppos + rcount > crt_size)
rcount = crt_size - *ppos;
ret = copy_to_user(buf, &content[*ppos], rcount);
if (ret != 0) {
pr_warning("@read: copy to user failed\n");
return -EFAULT;
}
pr_debug("@read: requested %d, received %d, current pos %lld\n",
count, rcount, *ppos);
*ppos += rcount;
return rcount;
}
开发者ID:alexandrucomanescu,项目名称:ASCPublic,代码行数:27,代码来源:nasty.c
示例6: random32
static const HDNode *generateKeyHandle(const uint8_t app_id[], uint8_t key_handle[])
{
uint8_t keybase[U2F_APPID_SIZE + KEY_PATH_LEN];
// Derivation path is m/U2F'/r'/r'/r'/r'/r'/r'/r'/r'
uint32_t key_path[KEY_PATH_ENTRIES];
for (uint32_t i = 0; i < KEY_PATH_ENTRIES; i++) {
// high bit for hardened keys
key_path[i]= 0x80000000 | random32();
}
// First half of keyhandle is key_path
memcpy(key_handle, key_path, KEY_PATH_LEN);
// prepare keypair from /random data
const HDNode *node = getDerivedNode(key_path, KEY_PATH_ENTRIES);
if (!node)
return NULL;
// For second half of keyhandle
// Signature of app_id and random data
memcpy(&keybase[0], app_id, U2F_APPID_SIZE);
memcpy(&keybase[U2F_APPID_SIZE], key_handle, KEY_PATH_LEN);
hmac_sha256(node->private_key, sizeof(node->private_key),
keybase, sizeof(keybase), &key_handle[KEY_PATH_LEN]);
// Done!
return node;
}
开发者ID:keepkey,项目名称:keepkey-firmware,代码行数:29,代码来源:u2f.c
示例7: yam_arbitrate
static void yam_arbitrate(struct net_device *dev)
{
struct yam_port *yp = netdev_priv(dev);
if (yp->magic != YAM_MAGIC || yp->tx_state != TX_OFF ||
skb_queue_empty(&yp->send_queue))
return;
/* tx_state is TX_OFF and there is data to send */
if (yp->dupmode) {
/* Full duplex mode, don't wait */
yam_start_tx(dev, yp);
return;
}
if (yp->dcd) {
/* DCD on, wait slotime ... */
yp->slotcnt = yp->slot / 10;
return;
}
/* Is slottime passed ? */
if ((--yp->slotcnt) > 0)
return;
yp->slotcnt = yp->slot / 10;
/* is random > persist ? */
if ((random32() % 256) > yp->pers)
return;
yam_start_tx(dev, yp);
}
开发者ID:andi34,项目名称:Dhollmen_Kernel,代码行数:31,代码来源:yam.c
示例8: FDASSERT
void IChatHandler::_sCmd_Coin(IWorldPlayer *_player, const char *_message)
{
FDASSERT(_player);
FDASSERT(_message);
_player->greenText((random32() & 1) ? "heads" : "tails");
}
开发者ID:coolzazzou,项目名称:Black-Orion,代码行数:7,代码来源:ChatHandler.cpp
示例9: random32
/*search in cache*/
dsn::rpc_address replication_app_client_base::get_address(bool is_write, read_semantic_t semantic, const partition_configuration& config)
{
if (is_write || semantic == read_semantic_t::ReadLastUpdate)
return config.primary;
// readsnapshot or readoutdated, using random
else
{
bool has_primary = false;
int N = static_cast<int>(config.secondaries.size());
if (!config.primary.is_invalid())
{
N++;
has_primary = true;
}
if (0 == N) return config.primary;
int r = random32(0, 1000) % N;
if (has_primary && r == N - 1)
return config.primary;
else
return config.secondaries[r];
}
}
开发者ID:Strongc,项目名称:rDSN,代码行数:26,代码来源:replication_app_client_base.cpp
示例10: do_operation
static int do_operation(void)
{
if (random32() & 1)
return do_read();
else
return do_write();
}
开发者ID:morristech,项目名称:linux,代码行数:7,代码来源:mtd_stresstest.c
示例11: lockSources
void gravManager::addTestObject()
{
lockSources();
RectangleBase* obj = new RectangleBase( 0.0f, 0.0f );
drawnObjects->push_back( obj );
bool useRandName = false;
if ( useRandName )
{
int nameLength = 10;
std::string randName;
for( int i = 0; i < nameLength; i++ )
{
int rand = ((float)random32() / (float)random32_max() * 95) + 32;
randName += (char)rand;
}
obj->setName( randName );
}
else if ( drawnObjects->size() % 2 == 0 )
{
obj->setName( " " );
}
else
{
obj->setName( "TEST" );
}
Texture t = GLUtil::getInstance()->getTexture( "border" );
obj->setTexture( t.ID, t.width, t.height );
obj->setUserDeletable( true );
unlockSources();
}
开发者ID:icompuiz,项目名称:grav,代码行数:32,代码来源:gravManager.cpp
示例12: c4iw_id_table_alloc
int c4iw_id_table_alloc(struct c4iw_id_table *alloc, u32 start, u32 num,
u32 reserved, u32 flags)
{
int i;
alloc->start = start;
alloc->flags = flags;
if (flags & C4IW_ID_TABLE_F_RANDOM)
alloc->last = random32() % RANDOM_SKIP;
else
alloc->last = 0;
alloc->max = num;
spin_lock_init(&alloc->lock);
alloc->table = kmalloc(BITS_TO_LONGS(num) * sizeof(long),
GFP_KERNEL);
if (!alloc->table)
return -ENOMEM;
bitmap_zero(alloc->table, num);
if (!(alloc->flags & C4IW_ID_TABLE_F_EMPTY))
for (i = 0; i < reserved; ++i)
set_bit(i, alloc->table);
return 0;
}
开发者ID:3null,项目名称:fastsocket,代码行数:25,代码来源:id_table.c
示例13: DECLARE_TEST
DECLARE_TEST( ringbuffer, io )
{
ringbuffer_t* buffer;
char from[256];
char to[256];
unsigned int size, verify, loop, loops;
unsigned int expected_size = 0;
for( size = 0; size < 256; ++size )
from[size] = (char)( random32() & 0xFF );
buffer = ringbuffer_allocate( 512 );
loops = 32;
for( loop = 0; loop < loops; ++loop )
{
for( size = 0; size < 256; ++size )
{
ringbuffer_write( buffer, from, size );
ringbuffer_read( buffer, to, size );
for( verify = 0; verify < size; ++verify )
EXPECT_EQ( to[verify], from[verify] );
expected_size += size;
}
}
EXPECT_EQ( ringbuffer_total_read( buffer ), expected_size );
EXPECT_EQ( ringbuffer_total_written( buffer ), expected_size );
ringbuffer_deallocate( buffer );
return 0;
}
开发者ID:DanielTillett,项目名称:foundation_lib,代码行数:33,代码来源:main.c
示例14: nat64_binding_create
/**
* Allocate a new binding. Try using the same port as on the IPv6 side.
* If it's already in use, allocate one randomly. The binding is inserted into
* the Binding Information Base (BIB).
*
* \param bkey Initializer for the created binding.
*
* \return A pointer to the created binding if successful, NULL otherwise.
*/
static struct nat64_binding *
nat64_binding_create(const struct nat64_binding *bkey)
{
struct nat64_binding *b;
int min;
int max;
int first;
b = malloc(sizeof(*b));
if(!b) {
if(printk_ratelimit())
printk(KERN_DEBUG "nat64_binding_create: kmalloc failed");
return NULL;
}
*b = *bkey;
b->b_saddr4 = *(nat64_config_nat_addr());
b->b_sport4 = b->b_sport6;
if (!nat64_bib_insert(b))
return b;
min = b->b_sport6 < 1024 ? 0 : 1024;
max = b->b_sport6 < 1024 ? 1024 : 65536;
first = min + ((random32() % ((max - min) / 2) * 2) | (b->b_sport6 & 1));
if (nat64_binding_alloc_port(b, first, max) ||
nat64_binding_alloc_port(b, min, first))
return b;
kfree(b);
return NULL;
}
开发者ID:credil,项目名称:ecdysis,代码行数:43,代码来源:nf_nat64_session.c
示例15: c4iw_id_alloc
/*
* Trivial bitmap-based allocator. If the random flag is set, the
* allocator is designed to:
* - pseudo-randomize the id returned such that it is not trivially predictable.
* - avoid reuse of recently used id (at the expense of predictability)
*/
u32 c4iw_id_alloc(struct c4iw_id_table *alloc)
{
unsigned long flags;
u32 obj;
spin_lock_irqsave(&alloc->lock, flags);
obj = find_next_zero_bit(alloc->table, alloc->max, alloc->last);
if (obj >= alloc->max)
obj = find_first_zero_bit(alloc->table, alloc->max);
if (obj < alloc->max) {
if (alloc->flags & C4IW_ID_TABLE_F_RANDOM)
alloc->last += random32() % RANDOM_SKIP;
else
alloc->last = obj + 1;
if (alloc->last >= alloc->max)
alloc->last = 0;
set_bit(obj, alloc->table);
obj += alloc->start;
} else
obj = -1;
spin_unlock_irqrestore(&alloc->lock, flags);
return obj;
}
开发者ID:3null,项目名称:fastsocket,代码行数:32,代码来源:id_table.c
示例16: should_fail
bool should_fail(struct fault_attr *attr, ssize_t size)
{
if (attr->task_filter && !fail_task(attr, current))
return false;
if (atomic_read(&attr->times) == 0)
return false;
if (atomic_read(&attr->space) > size) {
atomic_sub(size, &attr->space);
return false;
}
if (attr->interval > 1) {
attr->count++;
if (attr->count % attr->interval)
return false;
}
if (attr->probability <= random32() % 100)
return false;
if (!fail_stacktrace(attr))
return false;
fail_dump(attr);
if (atomic_read(&attr->times) != -1)
atomic_dec_not_zero(&attr->times);
return true;
}
开发者ID:rrowicki,项目名称:Chrono_Kernel-1,代码行数:32,代码来源:fault-inject.c
示例17: main
int main(void)
{
__stack_chk_guard = random32();
setup();
memory_protect();
oledInit();
// at least one button is unpressed
uint16_t state = gpio_port_read(BTN_PORT);
if ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO) {
check_firmware_sanity();
oledClear();
oledDrawBitmap(40, 0, &bmp_logo64_empty);
oledRefresh();
uint8_t hash[32];
if (!signatures_ok(hash)) {
show_unofficial_warning(hash);
}
load_app();
}
bootloader_loop();
return 0;
}
开发者ID:klao,项目名称:trezor-mcu,代码行数:30,代码来源:bootloader.c
示例18: next_cid
uint32_t next_cid(void)
{
// extremely unlikely but hey
do {
cid = random32();
} while (cid == 0 || cid == CID_BROADCAST);
return cid;
}
开发者ID:keepkey,项目名称:keepkey-firmware,代码行数:8,代码来源:u2f.c
示例19: rand_len
static int rand_len(int offs)
{
unsigned int len;
len = random32();
len %= (bufsize - offs);
return len;
}
开发者ID:morristech,项目名称:linux,代码行数:8,代码来源:mtd_stresstest.c
示例20: rand_offs
static int rand_offs(void)
{
unsigned int offs;
offs = random32();
offs %= bufsize;
return offs;
}
开发者ID:morristech,项目名称:linux,代码行数:8,代码来源:mtd_stresstest.c
注:本文中的random32函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论