• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rand_s函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中rand_s函数的典型用法代码示例。如果您正苦于以下问题:C++ rand_s函数的具体用法?C++ rand_s怎么用?C++ rand_s使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rand_s函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: urner_bang

void urner_bang(t_urner *x)
{
    long rand;
    long size = sysmem_ptrsize(x->table); // RETURNS SIZE OF POINTER IN BYTES

#ifdef WIN_VERSION
	rand_s(&rand);
#else
	rand = random();
#endif

    rand = rand % size;

    if (x->count == size) {
        outlet_bang(x->bangout); // SEND A BANG WHEN WE'VE HIT MAXIMUM
        return;
    }
    
    if (x->table[rand] != 0) { // NUMBER HAS ALREADY BEEN CHOSEN
        do {
#ifdef WIN_VERSION
			rand_s(&rand);
#else
			rand = random();
#endif
            rand = rand % size;
        } while (x->table[rand] != 0);
    } 
    
    // WE GOT A NUMBER
    x->table[rand] = 1; // MARK THIS VALUE AS USED
    x->count++; // INCREMENT OUR COUNT
    outlet_int(x->out, rand);
}
开发者ID:Alfpercar,项目名称:MaxMSPExternals,代码行数:34,代码来源:urner.c


示例2: D3DXMatrixRotationZ

void CElementManager::CreateCircle(const D3DXVECTOR3& pos, FLOAT intensity, const SMap *map, 
			FLOAT lastTime, FLOAT length, INT max, DWORD color, BOOL isPlayer) 
{
	D3DXVECTOR3 dir;
	D3DXMATRIX trans;
	if (intensity > 1.f) intensity = 1.f;
	INT cnt = static_cast<INT>(max*intensity+0.5f);
	D3DXMatrixRotationZ(&trans, 2*D3DX_PI/cnt);
	UINT t;
	do {
		rand_s(&t);
		dir.x = t%10-5.f;
		rand_s(&t);
		dir.y = t%10-5.f;
	} while (dir.x == 0.f && dir.y == 0.f);
	dir.z = 0.f;
	D3DXVec3Normalize(&dir, &dir);
	if (isPlayer) 
		for (INT i(0); i < cnt; ++i) {
			D3DXVec3TransformNormal(&dir, &dir, &trans);
			m_pEcho.push_back(new CLine(pos, dir, 
				intensity, map, intensity <= 2.f/9, lastTime, length, color));
		}
	else 
		for (INT i(0); i < cnt; ++i) {
			D3DXVec3TransformNormal(&dir, &dir, &trans);
			m_pAmbience.push_back(new CLine(pos, dir, 
				intensity, map, intensity <= 2.f/9, lastTime, length, color));
		}

}
开发者ID:wyrover,项目名称:Echo,代码行数:31,代码来源:ElementManager.cpp


示例3: os_rand_r

/*
 * rand_r -- rand_r for windows
 *
 * XXX: RAND_MAX is equal 0x7fff on Windows, so to get 32 bit random number
 *	we need to merge two numbers returned by rand_s().
 *	It is not to the best solution as subsequences returned by rand_s are
 *	not guaranteed to be independent.
 *
 * XXX: Windows doesn't implement deterministic thread-safe pseudorandom
 *	generator (generator which can be initialized by seed ).
 *	We have to chose between a deterministic nonthread-safe generator
 *	(rand(), srand()) or a non-deterministic thread-safe generator(rand_s())
 *	as thread-safety is more important, a seed parameter is ignored in this
 *	implementation.
 */
int
os_rand_r(unsigned *seedp)
{
	UNREFERENCED_PARAMETER(seedp);
	unsigned part1, part2;
	rand_s(&part1);
	rand_s(&part2);
	return part1 << 16 | part2;
}
开发者ID:peluse,项目名称:nvml,代码行数:24,代码来源:os_windows.c


示例4: defined

    nonce Security::getNonce() {

        nonce n;
      #if defined(_WIN32)
        unsigned int a=0, b=0;
        rand_s(&a);
        rand_s(&b);
        n = (((unsigned long long)a)<<32) | b;
      #else
        n = (((unsigned long long)random())<<32) | random();
      #endif
        return n;
    }
开发者ID:2015520,项目名称:SequoiaDB,代码行数:13,代码来源:nonce.cpp


示例5: gen_xop_vpcmov

static size_t gen_xop_vpcmov(const void* ptr)
{
	// vpcmov xop ~rxb.08 W.vvvv.000 0xa2 /r ib[7:4]
	uint64_t* nextfree = (uint64_t*)ptr;
	uint64_t random = 0;
	size_t written = 0;
	rand_s((uint32_t*)&random);
	random <<= 32;
	rand_s((uint32_t*)&random);

	random &= 0x783f00f8e000u;
	random |= 0x00c0a200088fu;
	*nextfree = random;
	return 6;
}
开发者ID:dougives,项目名称:lilium,代码行数:15,代码来源:codegen.c


示例6: gen_xop_vpcom

static size_t gen_xop_vpcom(const void* ptr)
{
	// vpcom xop ~rxb.08 0.vvvv.000 0xcc /r ib
	uint64_t* nextfree = (uint64_t*)ptr;
	uint64_t random = 0;
	size_t written = 0;
	rand_s((uint32_t*)&random);
	random <<= 32;
	rand_s((uint32_t*)&random);

	random &= 0x073f2378e000u;
	random |= 0x00c0cc00088fu;
	*nextfree = random;
	return 6;
}
开发者ID:dougives,项目名称:lilium,代码行数:15,代码来源:codegen.c


示例7: gen_xop_vpperm

static size_t gen_xop_vpperm(const void* ptr)
{
	uint64_t* nextfree = (uint64_t*)ptr;
	uint64_t random = 0;
	rand_s((uint32_t*)&random);
	random <<= 32;
	rand_s((uint32_t*)&random);
	// vpperm: xop ~rxb.08 W.src1.000 0xa3 /r ib
	// but backwards ...
	// and out junk, or in goods
	random &= 0xf03f00f8e000u;
	random |= 0x00c0a300088fu;
	*nextfree = random;
	return 6;
}
开发者ID:dougives,项目名称:lilium,代码行数:15,代码来源:codegen.c


示例8: gen_xop_vprot

static size_t gen_xop_vprot(const void* ptr)
{
	// vprot xop ~rxb.09 W.vvvv.000 [0x90-0x93] /r
	uint64_t* nextfree = (uint64_t*)ptr;
	uint64_t random = 0;
	size_t written = 0;
	rand_s((uint32_t*)&random);
	random <<= 32;
	rand_s((uint32_t*)&random);

	random &= 0x3f03f8e000u;
	random |= 0xc09000098fu;
	*nextfree = random;
	return 5;
}
开发者ID:dougives,项目名称:lilium,代码行数:15,代码来源:codegen.c


示例9: rand_r

/**
 * Emulate rand_r() using rand_s() in a way that is enough for our needs.
 * Windows doesn't have rand_r(), and its rand_s() is different: It
 * returns an error indication and not the random number like rand_r().
 * The value it returns is through its argument.
 *
 * Note that "#define _CRT_RAND_S" is needed before "#include <stdlib.h>".
 */
int rand_r(unsigned int *s)
{
	rand_s(s);
	if (*s > INT_MAX) *s -= INT_MAX;

	return *s;
}
开发者ID:ampli,项目名称:link-grammar,代码行数:15,代码来源:utilities.c


示例10: srtp_cipher_rand

/*
 * A trivial platform independent random source.  The random
 * data is used for some of the cipher self-tests.
 */
static srtp_err_status_t srtp_cipher_rand (void *dest, uint32_t len) 
{
#if defined(HAVE_RAND_S)
  uint8_t *dst = (uint8_t *)dest;
  while (len)
  {
    unsigned int val;
    errno_t err = rand_s(&val);

    if (err != 0)
      return srtp_err_status_fail;
  
    *dst++ = val & 0xff;
    len--;
  }
#else
  /* Generic C-library (rand()) version */
  /* This is a random source of last resort */
  uint8_t *dst = (uint8_t *)dest;
  while (len)
  {
	  int val = rand();
	  /* rand() returns 0-32767 (ugh) */
	  /* Is this a good enough way to get random bytes?
	     It is if it passes FIPS-140... */
	  *dst++ = val & 0xff;
	  len--;
  }
#endif
  return srtp_err_status_ok;
}
开发者ID:Distrotech,项目名称:libsrtp,代码行数:35,代码来源:cipher.c


示例11: TRI_UInt32Random

uint32_t TRI_UInt32Random (void) {
#if RAND_MAX == 2147483647

  uint32_t l1;
  uint32_t l2;

  l1 = (uint32_t) TRI_random();
  l2 = (uint32_t) TRI_random();

  return ((l1 & 0xFFFF) << 16) | (l2 & 0xFFFF);

#else

#ifdef _WIN32
  unsigned int number;
  auto err = rand_s(&number);
  if (err == 0) {
    return number;
  }
#endif

  uint32_t l1;
  uint32_t l2;
  uint32_t l3;
  uint32_t l4;

  l1 = TRI_random();
  l2 = TRI_random();
  l3 = TRI_random();
  l4 = TRI_random();

  return ((l1 & 0xFF) << 24) | ((l2 & 0xFF) << 16) | ((l3 & 0xFF) << 8) | (l4 & 0xFF);
#endif
}
开发者ID:CoDEmanX,项目名称:ArangoDB,代码行数:34,代码来源:random.cpp


示例12: rand_s

void cSpelledByGinnyState::Enter( cHero* p_pHero )
{
	p_pHero->m_currFrame = 0;
	p_pHero->m_currAbnormalStep = 0;

	p_pHero->m_AbnormalType = SPELLED_BY_GINNY;

	//
	// deal with the ball
	//
	if( p_pHero->HaveGhostBall() )
	{
		unsigned int rnd;
		rand_s(&rnd);
		g_Balls[1]->SetPos(GAME_MAP_WIDTH / 2 - BALL_WIDTH / 2, 
			(int)((double)rnd / UINT_MAX * (GAME_MAP_HEIGHT - BALL_WIDTH)));
		((cGhostBall*)g_Balls[1])->m_pOwner = NULL;

		sSpeed spd;
		spd.vx = spd.vy = 0;
		g_Balls[1]->SetSpeed(spd);

		p_pHero->LoseBall();
	}

	g_SoundEffectIndex.push_back(SND_RON_GINNY_SPELLING);
}
开发者ID:cpylua,项目名称:Quidditch,代码行数:27,代码来源:HeroState.cpp


示例13: cryptoRandomCode

CString cryptoRandomCode (int iChars, DWORD dwFlags)

//	cryptoRandomCode
//
//	Generates a random code of the given number of characters from the following
//	set:
//
//	A-Z (except I and O)
//	2-9

	{
	if (iChars <= 0)
		return NULL_STR;

	//	Get the set

	char *pSet = g_AlphaCode32_set;
	int iSetSize = sizeof(g_AlphaCode32_set) - 1;

	//	Now generate a password of the appropriate number of characters

	CString sCode(iChars);
	char *pPos = sCode.GetParsePointer();
	char *pPosEnd = pPos + iChars;
	while (pPos < pPosEnd)
		{
		unsigned int dwRnd;
		rand_s(&dwRnd);
		*pPos++ = pSet[dwRnd % iSetSize];
		}

	//	Done

	return sCode;
	}
开发者ID:gmoromisato,项目名称:Hexarc,代码行数:35,代码来源:Crypto.cpp


示例14: smb_ntlm_generate_challenge

uint64_t    smb_ntlm_generate_challenge()
{
#if !defined(_WIN32)
    uint64_t        result;
    int             fd;

    fd = open(URANDOM, O_RDONLY);
    if (fd >= 0)
    {
        while(read(fd, (void *)&result, sizeof(result)) != sizeof(result))
            ;

        closesocket(fd);
        return result;
    }
    else
    {
        /* FIXME: Wrong on a arch with long is 32 bits */
        return random();
    }
#else
    unsigned int number;
    rand_s( &number );
    return number;
#endif
}
开发者ID:leshkoapps,项目名称:libdsm,代码行数:26,代码来源:smb_ntlm.c


示例15: dassert

    nonce64 Security::__getNonce() { 
        dassert( _initialized );
        nonce64 n;
#if defined(__linux__) || defined(__sunos__) || defined(__APPLE__)
        _devrandom->read((char*)&n, sizeof(n));
        massert(10355 , "devrandom failed", !_devrandom->fail());
#elif defined(_WIN32)
        unsigned a=0, b=0;
        assert( rand_s(&a) == 0 );
        assert( rand_s(&b) == 0 );
        n = (((unsigned long long)a)<<32) | b;
#else
        n = (((unsigned long long)random())<<32) | random();
#endif
        return n;
    }
开发者ID:RyokoAkizuki,项目名称:freshcity,代码行数:16,代码来源:nonce.cpp


示例16: abort

 int32_t PseudoRandom::nextInt32() {
     if ( rand_s(&_seed) == 0 ) {
         // SUCCESS
         return _seed;
     }
     abort();
 }
开发者ID:danpe91,项目名称:mongo,代码行数:7,代码来源:random.cpp


示例17: rand_s

void CTetrisDlg::NextRandomBlock()
{
    UINT r;
    rand_s(&r);
    m_gameParam &= 0x1F;
    m_gameParam |= ((BYTE)((DOUBLE)r / ((__int64)UINT_MAX + 1) * 7) + 1) << 5;
    m_nextColor = NextRandomColor();
}
开发者ID:zhangsu,项目名称:tetris,代码行数:8,代码来源:TetrisDlg.cpp


示例18: pal_rand32

uint32_t pal_rand32 ()
{
   unsigned int i_rand_number = 0;
   errno_t i_rand_ret = -1;

   i_rand_ret = rand_s(&i_rand_number);
   return (uint32_t) i_rand_number;
}
开发者ID:corehacker,项目名称:ch-pal,代码行数:8,代码来源:pal_general.c


示例19: fill_random

void fill_random(uint8_t* buffer, int len) {
    unsigned int number;
    int i = 0;

    for (i=0; i < len; ++i) {
        rand_s(&number);
        buffer[i] = (number%256);
    }
}
开发者ID:DorChen,项目名称:dibbler,代码行数:9,代码来源:lowlevel-win32.c


示例20: rand_s

unsigned
random_device::operator()()
{
    unsigned r;
    errno_t err = rand_s(&r);
    if (err)
        __throw_system_error(err, "random_device rand_s failed.");
    return r;
}
开发者ID:leaningtech,项目名称:cheerp-libcxx,代码行数:9,代码来源:random.cpp



注:本文中的rand_s函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ randcalc函数代码示例发布时间:2022-05-30
下一篇:
C++ rand_range函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap