当前位置: 首页>>代码示例>>C++>>正文


C++ PRNG类代码示例

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


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

示例1: baseOT

OTExtensionWithMatrix OTExtensionWithMatrix::setup(TwoPartyPlayer& player,
        int128 delta, OT_ROLE role, bool passive)
{
    BaseOT baseOT(128, 128, &player, INV_ROLE(role));
    PRNG G;
    G.ReSeed();
    baseOT.set_receiver_inputs(delta);
    baseOT.exec_base(false);
    return OTExtensionWithMatrix(baseOT, &player, passive);
}
开发者ID:lance6716,项目名称:SPDZ-2,代码行数:10,代码来源:OTExtensionWithMatrix.cpp

示例2: randomize

void BitMatrixSlice::randomize(int row, PRNG& G)
{
    const int block_size = RAND_SIZE / sizeof(bm.squares[0].rows[0]);
    auto iSquare = bm.squares.begin() + start;
    for ( ; iSquare < bm.squares.end() - block_size; )
    {
        G.next();
        for (int j = 0; j < block_size; j++)
            (iSquare++)->rows[row] = G.get_doubleword_no_check();
    }
    for ( ; iSquare < bm.squares.end(); iSquare++)
        iSquare->randomize(row, G);
}
开发者ID:bristolcrypto,项目名称:apricot,代码行数:13,代码来源:BitMatrix.cpp

示例3: main

int main()
{
    RC4 rc4;
    PRNG *prng = &rc4;
    prng->initialize("Key");
    for(int x = 0; x < 10; x++)
        std::cout << std::hex << (int) prng->get_byte() << " ";
    std::cout << std::endl;

    prng->initialize("Key");
    for(int x = 0; x < 15; x++)
        std::cout << std::hex << (int) prng->get_byte() << " ";
    std::cout << std::endl;
    return 0;
}
开发者ID:8dexc,项目名称:8CT,代码行数:15,代码来源:test.cpp

示例4: main

int main()
{
	//std::ofstream fout("Tests.txt");
	PRNG randoms;
	//Build vector of functions for later use
	std::vector<void (*)(std::vector<int>&, bool, std::ostream&)> fasts;
	fasts.push_back(NaiveQuickSort);
	fasts.push_back(QuickSortMedian);
	fasts.push_back(QuickSort);

	//Test the multithreaded algorithms
	cout <<"\n----Testing Algorithms----\n";
	for(unsigned int i = 0; i < fasts.size(); i++)
	{
		//Build test vectors
		std::vector<int> rands;
		for(unsigned int j = 0; j < 10000000; j++)
		{
			rands.push_back(randoms.randInt());
		}
		if(i==0)
			cout << "Naive Algorithm----\n";
		if(i==1)
			cout << "Adding Median of Three----\n";
		if(i==2)
			cout << "Multithreading, Median of Three, ShellSort on small data---\n";
		SortOperation(rands, fasts[i], cout);
		cout << "\n";
	}
	//Test the std::sort method as well
	std::vector<int> rands;
	for(unsigned int j = 0; j < 10000000; j++)
	{
		rands.push_back(randoms.randInt());
	}
	cout << "Testing std::sort---\n";
	clock_t start = clock();
	std::sort(rands.begin(),rands.end());
	clock_t finish = clock();
	cout << (static_cast<double>(finish - start) / static_cast<double>(CLOCKS_PER_SEC));
	cout << std::endl;

	//fout.close();
	system("PAUSE");
	return 0;
}
开发者ID:mlh758,项目名称:School-Projects,代码行数:46,代码来源:Source.cpp

示例5: Create_Random_Seed

void MAC_Check<T>::Check(const Player& P)
{
  if (WaitingForCheck() == 0)
    return;

  //cerr << "In MAC Check : " << popen_cnt << endl;
  octet seed[SEED_SIZE];
  this->timers[SEED].start();
  Create_Random_Seed(seed,P,SEED_SIZE);
  this->timers[SEED].stop();
  PRNG G;
  G.SetSeed(seed);

  Share<T>  sj;
  T a,gami,h,temp;
  a.assign_zero();
  gami.assign_zero();
  vector<T> tau(P.num_players());
  for (int i=0; i<popen_cnt; i++)
    { h.almost_randomize(G);
      temp.mul(h,vals[i]);
      a.add(a,temp);
      
      temp.mul(h,macs[i]);
      gami.add(gami,temp);
    }
  vals.erase(vals.begin(), vals.begin() + popen_cnt);
  macs.erase(macs.begin(), macs.begin() + popen_cnt);
  temp.mul(this->alphai,a);
  tau[P.my_num()].sub(gami,temp);

  //cerr << "\tCommit and Open" << endl;
  this->timers[COMMIT].start();
  Commit_And_Open(tau,P);
  this->timers[COMMIT].stop();

  //cerr << "\tFinal Check" << endl;

  T t;
  t.assign_zero();
  for (int i=0; i<P.num_players(); i++)
    { t.add(t,tau[i]); }
  if (!t.is_zero()) { throw mac_fail(); }

  popen_cnt=0;
}
开发者ID:lance6716,项目名称:SPDZ-2,代码行数:46,代码来源:MAC_Check.cpp

示例6: render

void HistogramImage::render(std::vector<unsigned char> &rgb, double scale, double exponent)
{
    // Tone mapping from 64-bit-per-channel to 8-bit-per-channel, with dithering.

    PRNG rng;
    rng.seed(0);

    unsigned i = 0;
    unsigned e = mWidth * mHeight * kChannels; 
    rgb.resize(e);

    for (; i != e; ++i) {
        double u = std::max(0.0, mCounts[i] * scale);
        double dither = rng.uniform();
        double v = 255.0 * pow(u, exponent) + dither;
        rgb[i] = std::max(0.0, std::min(255.9, v));
    }
}
开发者ID:B-Rich,项目名称:zenphoton,代码行数:18,代码来源:histogramimage.cpp

示例7: main

int main(){
    unsigned int seed_value[32]; 
    for(int i=0; i<32; i++){
        seed_value[i] = i*2;    // Arbitrary seed value
    }

    InitWELLRNG1024a(seed_value);
    
    PRNG* rng = PRNGFactory::generatePRNG("well");
    rng->set(seed_value);
    
    for(int i=0; i<10; i++){
        double original_generator = WELLRNG1024a();
        double PRNGFactory_generator = rng->get_double();
        std::cout << original_generator << " " << PRNGFactory_generator << "\n";
        if(original_generator != PRNGFactory_generator){
            std::cout << "The streams do not match\n";
            exit(0);
        }
    }

    high_resolution_clock::time_point t1, t2;
    
    // Measure the time it takes the original generator to produce 1 billion values
    t1 = high_resolution_clock::now();
    for(int i=0; i<1000000000; i++){
        unsigned long original_stream = WELLRNG1024a();
    }
    t2 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>( t2 - t1 ).count();
    std::cout << "Original well generator used "<< duration << " microseconds to generate 1 billion values" << std::endl;

    // Measure the time it takes the new generator to produce 1 billion values
    t1 = high_resolution_clock::now();
    for(int i=0; i<1000000000; i++){
        unsigned long PRNG_stream = rng->get_double();
    }
    t2 = high_resolution_clock::now();
    duration = duration_cast<microseconds>( t2 - t1 ).count();
    std::cout << "PRNGFactory xorgens generator used "<< duration << " microseconds to generate 1 billion values" << std::endl;

    return 0;
}
开发者ID:plempert,项目名称:prnglib,代码行数:43,代码来源:test_well.cpp

示例8: zero

void PartSetup<FD>::insecure_debug_keys(vector<PartSetup<FD> >& setups, int nplayers, bool simple_pk)
{
    cout << "generating INSECURE keys for debugging" << endl;
    setups.clear();
    Rq_Element zero(params, evaluation, evaluation),
            one(params, evaluation, evaluation);
    zero.assign_zero();
    one.assign_one();
    PRNG G;
    G.ReSeed();
    if (simple_pk)
        pk.assign(zero, zero, zero, zero - one);
    else
        pk.KeyGen(one, G, nplayers);
    setups.resize(nplayers, *this);
    setups[0].sk.assign(one);
    for (int i = 1; i < nplayers; i++)
        setups[i].sk.assign(zero);
}
开发者ID:lance6716,项目名称:SPDZ-2,代码行数:19,代码来源:DataSetup.cpp

示例9: randomizeRow

// For now, this just directly puts them into 'frags'
void Board::randomizeRow(unsigned int i) {
  unsigned int maxInt = 8; // the higher, the more blank spaces
  //maxInt = 400; // good to keep whole pieces separate
  //    maxInt = 8;  // good for individual squares
  PRNG* rng = Tetris::TApp::theApp->rng;
  int j = rng->uniform() % clms;
  auto k = nFromIJ(i, j);
  unsigned int pi = rng->uniform() % maxInt;
  TCode p = ((1 <= pi) && (pi <= 7)) ? ((TCode)pi) : N;
  if (N != p) {
    Shape s = Shape(p);
    s.setRandomShape();
    bool ok = testShape(s, i, j);
    if (ok) {
      placeShape(s,i,j);
      s.showCoords();
      cout << endl << flush;
    }
  }
  return;
}
开发者ID:KAPSARC,项目名称:KTAB,代码行数:22,代码来源:board.cpp

示例10: while

unsigned Random<T_PRNG>::CalcChecksum(const PRNG& rng)
{
    // This is designed in a way that makes the checksum be equivalent
    // to the state of the OldLCG for compatibility with old versions
    Serializer ser;
    rng.serialize(ser);
    unsigned checksum = 0;
    while(ser.GetBytesLeft() >= sizeof(unsigned))
        checksum += ser.PopUnsignedInt();
    while(ser.GetBytesLeft())
        checksum += ser.PopUnsignedChar();
    return checksum;
}
开发者ID:Return-To-The-Roots,项目名称:s25client,代码行数:13,代码来源:Random.cpp

示例11: insecure

void PartSetup<FD>::fake(vector<FHE_SK>& sks, vector<T>& alphais,
        int nplayers, bool distributed)
{
  insecure("global key generation");
  if (distributed)
      cout << "Faking distributed key generation" << endl;
  else
      cout << "Faking key generation with extra noise" << endl;
  PRNG G;
  G.ReSeed();
  pk = FHE_PK(params, FieldD.get_prime());
  FHE_SK sk(params, FieldD.get_prime());
  calpha = Ciphertext(params);
  sks.resize(nplayers, pk);
  alphais.resize(nplayers);

  if (distributed)
      DistKeyGen::fake(pk, sks, FieldD.get_prime(), nplayers);
  else
  {
      Rq_Element sk = FHE_SK(pk).s();
      for (int i = 0; i < nplayers; i++)
      {
          Rq_Element ski = pk.sample_secret_key(G);
          sks[i].assign(ski);
          sk += ski;
      }
      pk.KeyGen(sk, G, nplayers);
  }

  for (int i = 0; i < nplayers; i++)
    {
      Plaintext_<FD> m(FieldD);
      m.randomize(G,Diagonal);
      Ciphertext calphai = pk.encrypt(m);
      calpha += calphai;
      alphais[i] = m.element(0);
    }
}
开发者ID:lance6716,项目名称:SPDZ-2,代码行数:39,代码来源:DataSetup.cpp

示例12: init

void Zobrist::init()
{
	PRNG prng;
	// turn
	turn = prng.next64();

	// epFile
	for (int i=0; i<8; i++)
		epFile[i] = prng.next64();

	// piece
	memset( piece, 0, sizeof(piece) );
	for (Color c=ctWhite; c<=ctBlack; c++)
		for (Piece p=ptPawn; p<=ptKing; p++)
			for (Square sq = 0; sq < 64; sq++ )
				piece[c][p][sq] = prng.next64();

	// castling
	cast[ ctWhite ][0] = cast[ ctBlack ][0] = 0;
	for (Color c=ctWhite; c<=ctBlack; c++)
		for (uint i=1; i<=0x88; i++)
			cast[c][i] = prng.next64();
}
开发者ID:kmar,项目名称:cheng4,代码行数:23,代码来源:zobrist.cpp

示例13: gettimeofday

void OTExtensionWithMatrix::transfer(int nOTs,
                                     const BitVector& receiverInput)
{
#ifdef OTEXT_TIMER
    timeval totalstartv, totalendv;
    gettimeofday(&totalstartv, NULL);
#endif
    cout << "\tDoing " << nOTs << " extended OTs as " << role_to_str(ot_role) << endl;
    if (nOTs % nbaseOTs != 0)
        throw invalid_length(); //"nOTs must be a multiple of nbaseOTs\n");
    if (nOTs == 0)
        return;
    // add k + s to account for discarding k OTs
    nOTs += 2 * 128;

    int slice = nOTs / nsubloops / 128;
    BitMatrix t1(nOTs), u(nOTs);
    senderOutputMatrices.resize(2, BitMatrix(nOTs));
    // resize to account for extra k OTs that are discarded
    PRNG G;
    G.ReSeed();
    BitVector newReceiverInput(nOTs);
    for (unsigned int i = 0; i < receiverInput.size_bytes(); i++)
    {
        newReceiverInput.set_byte(i, receiverInput.get_byte(i));
    }

    //BitVector newReceiverInput(receiverInput);
    newReceiverInput.resize(nOTs);

    receiverOutputMatrix.resize(nOTs);

    for (int loop = 0; loop < nloops; loop++)
    {
        // randomize last 128 + 128 bits that will be discarded
        for (int i = 0; i < 4; i++)
            newReceiverInput.set_word(nOTs/64 - i, G.get_word());

        // subloop for first part to interleave communication with computation
        for (int start = 0; start < nOTs / 128; start += slice)
        {
            vector<octetStream> os(2);

            BitMatrixSlice receiverOutputSlice(receiverOutputMatrix, start, slice);
            BitMatrixSlice senderOutputSlices[2] = {
                BitMatrixSlice(senderOutputMatrices[0], start, slice),
                BitMatrixSlice(senderOutputMatrices[1], start, slice)
            };
            BitMatrixSlice t1Slice(t1, start, slice);
            BitMatrixSlice uSlice(u, start, slice);

            // expand with PRG and create correlation
            if (ot_role & RECEIVER)
            {
                for (int i = 0; i < nbaseOTs; i++)
                {
                    receiverOutputSlice.randomize(i, G_sender[i][0]);
                    t1Slice.randomize(i, G_sender[i][1]);
                }

                t1Slice ^= receiverOutputSlice;
                t1Slice ^= newReceiverInput;
                t1Slice.pack(os[0]);

//                t1 = receiverOutputMatrix;
//                t1 ^= newReceiverInput;
//                receiverOutputMatrix.print_side_by_side(t1);
            }
#ifdef OTEXT_TIMER
            timeval commst1, commst2;
            gettimeofday(&commst1, NULL);
#endif
            // send t0 + t1 + x
            send_if_ot_receiver(player, os, ot_role);

            // sender adjusts using base receiver bits
            if (ot_role & SENDER)
            {
                for (int i = 0; i < nbaseOTs; i++)
                    // randomize base receiver output
                    senderOutputSlices[0].randomize(i, G_receiver[i]);

                // u = t0 + t1 + x
                uSlice.unpack(os[1]);
                senderOutputSlices[0].conditional_xor(baseReceiverInput, u);
            }
#ifdef OTEXT_TIMER
            gettimeofday(&commst2, NULL);
#ifdef VERBOSE
            double commstime = timeval_diff(&commst1, &commst2);
            cout << "\t\tCommunication took time " << commstime/1000000 << endl << flush;
#endif
            times["Communication"] += timeval_diff(&commst1, &commst2);
#endif

            // transpose t0[i] onto receiverOutput and tmp (q[i]) onto senderOutput[i][0]

#ifdef VERBOSE
            cout << "Starting matrix transpose\n" << flush << endl;
#endif
//.........这里部分代码省略.........
开发者ID:bristolcrypto,项目名称:apricot,代码行数:101,代码来源:OTExtensionWithMatrix.cpp

示例14: main

int main(int ac, char **av) {
  el::Configurations confFromFile("./rpdemo-logger.conf");
  el::Loggers::reconfigureAllLoggers(confFromFile);

  using KBase::ReportingLevel;
  using KBase::PRNG;
  using KBase::MtchPstn;
  using KBase::dSeed;
  using RfrmPri::RPModel;
  using RfrmPri::RPState;
  using RfrmPri::RPActor;
  //using RfrmPri::printPerm;

  auto sTime = KBase::displayProgramStart(RfrmPri::appName, RfrmPri::appVersion);
  uint64_t seed = dSeed; // arbitrary;
  bool siP = true;
  bool cpP = false;
  bool runP = true;
  unsigned int sNum = 1;
  bool xmlP = false;
  bool rp2P = false;
  std::string inputXML = "";

  auto showHelp = [sNum]() {
    printf("\n");
    printf("Usage: specify one or more of these options\n");
    printf("\n");
    printf("--cp              start all actors from the central position \n");
    printf("--rp2             create RP2 objects \n");
    printf("--si              start each actor from their most self-interested position \n");
    printf("                  If neither si nor cp are specified, it will use si. \n");
    printf("                  If both si and cp are specified, it will use second specified. \n");
    printf("--help            print this message and exit \n");
    printf("--seed <n>        set a 64bit seed \n");
    printf("                  0 means truly random \n");
    printf("                  default: %020llu \n", dSeed);
    printf("--sNum <n>        choose a scenario number \n");
    printf("                  default: %u \n", sNum);
    printf("                  0: random example, potentially VERY large \n");
    printf("                  1: hard-coded example, moderate size \n");
    printf("--xml <f>         read XML scenario from a given file \n");
    printf("\n");
    printf("For example, rpdemo --si  --xml rpdata.xml, would read the file rpdata.xml \n");
    printf("and start all actors from self-interested positions.\n");
    printf("\n");
    printf("If both scenario number and XML file are specified, it will use only the XML.\n");
    printf("\n");
    printf("If neither scenario number nor XML file are specified, \n");
    printf("it will run a hard-coded example, as if --sNum 1 had been specified.\n");
    printf("\n");
  };

  // a list of <keyword, description, λ-fn>
  // might be enough to do this - except for the arguments to options.
  if (ac > 1) {
    for (int i = 1; i < ac; i++) {
      if (strcmp(av[i], "--seed") == 0) {
        i++;
        seed = std::stoull(av[i]);
      }
      else if (strcmp(av[i], "--sNum") == 0) {
        i++;
        sNum = atoi(av[i]);
      }
      else if (strcmp(av[i], "--xml") == 0) {
        xmlP = true;
        i++;
        inputXML = av[i];
      }
      else if (strcmp(av[i], "--rp2") == 0) {
        rp2P = true;
      }
      else if (strcmp(av[i], "--si") == 0) {
        cpP = false;
        siP = true;
      }
      else if (strcmp(av[i], "--cp") == 0) {
        siP = false;
        cpP = true;
      }
      else if (strcmp(av[i], "--help") == 0) {
        runP = false;
      }
      else {
        runP = false;
        printf("Unrecognized argument: %s\n", av[i]);
      }
    }
  }
  else {
    runP = false;
  }

  if (!runP) {
    showHelp();
    return 0;
  }


  if (0 == seed) {
//.........这里部分代码省略.........
开发者ID:ambah,项目名称:KTAB,代码行数:101,代码来源:reformpriorities.cpp

示例15:

void square128::randomize(int row, PRNG& G)
{
    rows[row] = G.get_doubleword();
}
开发者ID:bristolcrypto,项目名称:apricot,代码行数:4,代码来源:BitMatrix.cpp


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