Example #1
0
Perlin::Perlin(int seed, int sx, int sy, double min, double max, int st, int oc, double pers) : sizeX(sx), sizeY(sy), step(st), octaves(oc), persistence(pers) 
{
	auto g = seed == 0 ? Generator() : Generator(seed);
	int maxWidth = (int) ceil(sizeX * pow(2, octaves - 1) / step);
	int maxHeight = (int) ceil(sizeY * pow(2, octaves - 1) / step);
	v = g.randomDouble(min, max, maxWidth * maxHeight);
}
Example #2
0
int main(int argc, char** argv)
{
	//Generator obj(4);

	std::deque<int> mydeque(5);
	std::generate(mydeque.begin(), mydeque.end(), Generator(4));

	std::ostream_iterator<int> out_it (std::cout, "; ");
    copy (mydeque.begin(), mydeque.end(), out_it);
    std::cout << std::endl;

    std::vector<int> s1(5);
    copy(mydeque.begin(), mydeque.end(), s1.begin());
    copy (s1.begin(), s1.end(), out_it);
    std::cout << std::endl;

    mydeque.clear();

    std::vector<int> s2(10);
    std::generate(s2.begin(), s2.end(), Generator(2));
    copy (s2.begin(), s2.end(), out_it);
    std::cout << std::endl;

    std::vector<int> s3;
    //generate_n 
    std::back_insert_iterator<std::vector<int> > it (s3);
    generate_n(it, 6, Generator(3));

    copy (s3.begin(), s3.end(), out_it);
    std::cout << std::endl;

    std::cout << "s1 contenu dans s2 : " << (includes(s1.begin(), s1.end(), s2.begin(), s2.end()) ? "true" : "false") << std::endl;

	return 0;
}
Example #3
0
void AbelianEquationsSolver::makeSystem()
{
  for( int i = 0 ; i < rawSystem.length() ; i++ )
    {
      for( int j = 0 ; j < rawSystem[i].length() ; j++ )
	{
	  Generator g = rawSystem[i][j];
	  
	  if( abs( g.hash() ) > numberOfVariables )
	    {
	      Generator newg;
	      if( g.hash() > 0 )
		newg = Generator( g.hash() - numberOfVariables );
	      else
		newg = Generator( g.hash() + numberOfVariables );
	      
	      b[i] *= inv(newg);
	    }
	  else
	    system[i] *= g;
	}
      
      system[i] = system[i].freelyReduce();
      b[i] = b[i].freelyReduce();
    }
}
Example #4
0
void DumpPresenter::UpdateContents()
{
	do {
		wxString text;
		OutputString output(text);
		Generator(_vm, output).GenerateHtmlDump(
					Config::Get()->dumpPresenterAddrBin,
					Config::Get()->dumpPresenterColumns, false);
		do {
			wxString textFramed;
			textFramed += wxT("<html><body>\n");
			textFramed += text;
			textFramed += wxT("</body></html>\n");
			_pHtmlWindow->SetPage(textFramed);
		} while (0);
		do {
			_pTextHtml->SetValue(text);
		} while (0);
	} while (0);
	do {
		wxString text;
		OutputString output(text);
		Generator(_vm, output).GenerateHex(true, Config::Get()->dumpPresenterColumns);
		do {
			_pTextDmp->SetValue(text);
		} while (0);
	} while (0);
}
Example #5
0
void MalcevSet::makeFull() const {

  if( isBasis ) return;

  MalcevSet *This = (MalcevSet *)this;  // to break physical constness
  const BasicCommutators& BC = theCollector.commutators();
  int nilClass = BC.nilpotencyClass();

  // add all commutators [Wj, Wi]

  int upper_i =  BC.theFirstOfWeight(nilClass);

  for(int i = 2; i < upper_i; i++) {

    if( ! theSet.bound( Generator(i) ) ) continue;
    PolyWord Wi = theSet.valueOf( Generator(i) );
    int upper_j = 
      BC.theFirstOfWeight( nilClass - BC.weightOf(i) + 1);

    if( upper_j > i ) upper_j = i;

    for(int j = 1; j < upper_j; j++) {

      if( ! theSet.bound( Generator(j) ) ) continue;

      PolyWord Wj = theSet.valueOf( Generator(j) );

      PolyWord comm = makeCommutator(Wj, Wi);
      This->addWord(comm);
    }
  }
  This->isBasis = true;
}
Example #6
0
bool MalcevSet::isNormalClosure() const {

  if( isNormal != dontknow ) return isNormal;

  if( ! isBasis )
    error("Attempt to use MalcevSet::isNormalClosure before the set is full.");

  const BasicCommutators& BC = theCollector.commutators();
  MalcevSet* This = (MalcevSet *)this;    // to break physical constness

  //the subgroup is normal iff any w^x is in the set

  for(int i = 1; i < BC.theFirstOfWeight(BC.nilpotencyClass() ); i++) {

    if( ! theSet.bound( Generator(i) ) ) continue;
    PolyWord W = theSet.valueOf( Generator(i) );
    
    for(int j = 1; j <= BC.numberOfGenerators(); j++) {

      PolyWord conj = collect( Letter(j, -1) * W * Letter(j, 1) );

      checkMembership(conj);

      if(! conj.isEmpty() ) {
	This->isNormal = no;
	return false;
      }
    }
  }
  This->isNormal = yes;
  return true;
}
Example #7
0
void MalcevSet::printOn(ostream& s) const {

  const BasicCommutators& BC = theCollector.commutators();

  for(int key = 1; key <= BC.theHirschNumber(); key++) {
    if( theSet.bound( Generator(key) ) ) {
      PolyWord pw = theSet.valueOf( Generator(key) );
      s << BC.wordForm().asCommutatorWord(pw) << endl;
    }
  }
}
Example #8
0
AbelianEquationsSolver::AbelianEquationsSolver( const AbelianGroup& a , 
						const VectorOf<Word>& v ,
						int numOfVar )
  : rawA( a ),
    A( FPGroup() ),
    rawSystem( v ),
    system( v.length() ),
    b( v.length() ),
    x( numOfVar ),
    torsion( numOfVar ),
    params( numOfVar ),
    numberOfVariables( numOfVar ),
    sysRank( 0 ),
    haveSol( -1 )
{
  FPGroup G( a.getFPGroup() );
  VectorOf<Chars> q( G.numberOfGenerators() - numberOfVariables );
  
  for( int i = numberOfVariables ; i < G.numberOfGenerators() ; i++ )
    q[ i - numberOfVariables ] = (G.namesOfGenerators())[i];
  
  if( G.getRelators().cardinality() )
    {
      SetOf<Word> s = G.getRelators();
      SetIterator<Word> I(s);
      SetOf<Word> news;
      
      while( !I.done() )
	{
	  Word w = I.value();
	  for( int j = 0 ; j < w.length() ; j++ )
	    {
	      int p = Generator( w[j] ).hash();
	      if( p > 0 )
		w[j] = Generator( p - numberOfVariables );
	      else
		w[j] = Generator( p + numberOfVariables );
	    }
	  
	  news.adjoinElement( w );
	  I.next();
	}
      
      FPGroup G1( q , news );
      
      A = AbelianGroup( G1 );
    }
  else
    A = AbelianGroup( FPGroup(q) );
  
}
Example #9
0
// returns the basis as a vector of commutator words
VectorOf<PolyWord> MalcevSet::getPolyWords() const {

  VectorOf<PolyWord> res( cardinality() );
  int cnt = 0;

  const BasicCommutators& BC = theCollector.commutators();

  for(int key = 1; key <= BC.theHirschNumber(); key++) {
    if( theSet.bound( Generator(key) ) ) {
      PolyWord pw = theSet.valueOf( Generator(key) );
      res[cnt++] = pw;
    }
  }
  return res;
}
Example #10
0
void CMakeTool::fetchFromCapabilities() const
{
    Utils::SynchronousProcessResponse response = run({ "-E", "capabilities" }, true);
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return;

    auto doc = QJsonDocument::fromJson(response.stdOut().toUtf8());
    if (!doc.isObject())
        return;

    const QVariantMap data = doc.object().toVariantMap();
    m_hasServerMode = data.value("serverMode").toBool();
    const QVariantList generatorList = data.value("generators").toList();
    for (const QVariant &v : generatorList) {
        const QVariantMap gen = v.toMap();
        m_generators.append(Generator(gen.value("name").toString(),
                                      gen.value("extraGenerators").toStringList(),
                                      gen.value("platformSupport").toBool(),
                                      gen.value("toolsetSupport").toBool()));
    }

    const QVariantMap versionInfo = data.value("version").toMap();
    m_version.major = versionInfo.value("major").toInt();
    m_version.minor = versionInfo.value("minor").toInt();
    m_version.patch = versionInfo.value("patch").toInt();
    m_version.fullVersion = versionInfo.value("string").toByteArray();
}
Example #11
0
float neuron::randomize(const float& Minimum,const float& Maximum)
{
	random_device RandomDevice; //Initializes random engine
	mt19937 Generator(RandomDevice()); //Mersenne Twister 19937 generator, rng
	uniform_real_distribution<float> Distribution(Minimum, Maximum); //uniform probability distribution between Minimum and Maximum
	return Distribution(Generator); //Generate random weights
}
Example #12
0
IsEltCentral::IsEltCentral(const SMWord& word)
  : Supervisor( ! word.getParent().gic.haveFastWordProblem() ),
    theWord( word ),
    theChecker( word.getParent() ),
    normalClosure( *this, word.getParent().gcm().normalClosure ),
    abelianInvariants( *this, word.getParent().gcm().abelianInvariants ),
    kbSupervisor( *this, word.getParent().gcm().kbSupervisor ),
    agSupervisor( *this, word.getParent().gcm().agSupervisor ),
    computeBasis( *this, word.getParent().gcm().computeBasis ),
    nilpotentQuotients( *this, word.getParent().gcm().nilpotentQuotients ),
    nilpotentWPInQuotients(*this),
    nilpotentWP( *this ),
    genetic( *this )
{
  SetOf<Word> comms;
  int numOfGens = word.getParent().getFPGroup().numberOfGenerators();
  Word w = word.getWord();
  
  for( int i = 0; i < numOfGens; ++i ) {
    Word gen = Word(Generator(i+1));
    comms |= (w.inverse() * gen.inverse() * w * gen).freelyReduce();
  }

  theChecker.replaceTheSet(comms);
  nilpotentWP->initialize(comms,&theWord.getParent());
  nilpotentWPInQuotients->initialize(comms,&theWord.getParent());
  genetic->init(theWord.getParent().getFPGroup(), comms, 
		GeneticWPCM::COMMUTATORS);

  if ( !displayInFE() ) adminStart();
}
void RandomGenerator::init()
{
    typedef std::chrono::high_resolution_clock Clock;

    Clock::duration distance = Clock::now().time_since_epoch();
    __initGenerator = Generator(distance.count());
    __initDistrib = Distribution(0, distance.count());
}
Example #14
0
Word AbelianWordRep::getWord( ) const
{
  int powLen = thePowers.length();
  VectorOf<Generator> w( fullLength().as_long() );
  int k = 0;
  Integer power;
  
  for( int i = 0; i < powLen; ++i )
    if( sign( power = thePowers[i] ) >= 0 )
      for( int j = 0; j < power; ++j )
	w[k++] = Generator(i+1);
    else
      for( int j = 0; j < -power; ++j )
	w[k++] = Generator(-(i+1));

  return Word(w);
}
Example #15
0
void MalcevSet::makeNormalClosure() {

  if(isNormal == yes) return;

  const BasicCommutators& BC = theCollector.commutators();
  int nilClass = BC.nilpotencyClass();

  int upper_i = BC.theFirstOfWeight(nilClass);

  for(int i = 1; i <= upper_i; i++) {

    if( ! theSet.bound( Generator(i) ) ) continue;
    PolyWord Wi = theSet.valueOf( Generator(i) );
    PolyWord WiInv = Wi.inverse();

    // trying generators of the group

    for(int j = 1; j <= BC.numberOfGenerators(); j++) {

      Generator g(j); 
      PolyWord comm = collect( Wi * Letter(g,-1) * WiInv * Letter(g,1) ); 

      addWord(comm);
    }

    // trying basis elements

    int upper_j = BC.theFirstOfWeight(nilClass - BC.weightOf(i) + 1);
    if(upper_j > i) upper_j = i;

    for(int j = 1; j < upper_j; j++) {

      if( ! theSet.bound( Generator(j) ) ) continue;
      PolyWord Wj = theSet.valueOf( Generator(j) );

      PolyWord comm = collect( Wi * Wj * WiInv * Wj.inverse() );

      addWord(comm);
    }
  }
  isBasis = true;
  isNormal = yes;
}
Example #16
0
FPGroup FPGroup::triangulatePresentation( ) const
{
  int new_gen_num = numOfGenerators;
  char str[10];
  
  // rename old generators to avoid collisions
  vector< string > new_gen_names = initializeGenNames( numOfGenerators );
  vector< Word > new_relators;
  
  int new_gens_num = 0;
  for( vector< Word >::const_iterator r_it=theRelators.begin( ) ; r_it!=theRelators.end( ) ; ++r_it ) {
    
    const Word& rel = *r_it;
    int len = rel.length( );
    if( len>3 ) {

      // initial setup (first 3 letters)
      Word::const_iterator r_it = rel.begin( );
      int g1 = *r_it++;
      int g2 = *r_it++;
      int g3 = *r_it++;
      strstream(str,10) << (++new_gens_num) << ends;
      new_gen_names.push_back( string( "x" ).append( str ) );
      new_relators.push_back( Word( g1 )*Word( g2 )*Word( -new_gens_num ) );
      
      // iterations
      for( int i=0 ; i<len-4 ; ++i, ++r_it ) {
        strstream(str,10) << (++new_gens_num) << ends;
        new_gen_names.push_back( string( "x" ).append( str ) );
        int new_gen = new_gen_names.size( );
        new_relators.push_back( Word( new_gens_num-1 ) * Word(g3) * Generator( -new_gens_num ) );
        g3 = *r_it;
      }
      
      // the last relator
      new_relators.push_back( Word( g3 ) * Generator( *r_it ) * Word( -new_gens_num ) );
    } else
      new_relators.push_back( rel );
  }

  return FPGroup( FiniteAlphabet( new_gen_names) , new_relators );
}
Word AbelianSGPresentationRep::fromSGPGensToSGGens(const Word& w) const
{ 
  int i,j,m,n;
  m = theSGPGens.height();
  VectorOf<Integer> u(m);
  for(i=0; i<m; i++) u[i] = w.exponentSum(Generator(i+1));
  n = theSGPGens.width();
  VectorOf<Integer> v(n);
  for(j=0;j<n;j++) for(v[j]=i=0;i<m;i++) v[j] += u[i]*theSGPGens[i][j];
  return AbelianWord(v).getWord();
}
Example #18
0
Word GACPforORGSolverGene::randomWord( int gens , int wLen )
{
  Word w;

  do{
    int g = r.rand( 0 , gens-1 ) + 1;
    g *= 2 * r.rand( 0 , 1 ) - 1;    
    w *= Word( Generator( g ) );
    w = w.freelyReduce( );
  } while( w.length( )<wLen );
  
  return w;
}
Example #19
0
Word FPGroup::randomIdentity_Stack( int length ) const
{
  if( theRelators.size( )==0 )
    return Word();

  // 1. Construct a set of rules
  int ngens = numberOfGenerators( );
  int nrels = theRelators.size( );
  vector< pair< Word , Word > > rules;
  for( int r=0 ; r<nrels ; ++r ) {
    Word rel = theRelators[r];
    for( int l=0 ; l<rel.length() ; ++l ) {
      rel = rel.cyclicallyPermute( 1 );
      for( int p=0 ; p<=rel.length() ; ++p ) {
        Word left = rel.initialSegment( p );
        Word right = rel.terminalSegment( p );
        rules.push_back( pair< Word , Word >(  left ,  right ) );
        rules.push_back( pair< Word , Word >( -left , -right ) );
      }
    }
  }
  for( int i=0 ; i<ngens ; ++i ) {
    rules.push_back( pair< Word , Word >( Generator( i+1 ) , Generator( -i-1 ) ) );
    rules.push_back( pair< Word , Word >( Generator(-i-1 ) , Generator(  i+1 ) ) );
  }

  int rule_num = rules.size( );

  // 2. Construct a word using the rules
  Word result;
  while( result.length() < length ) {
    while( result.length() < length ) {
      int rn = RandLib::ur.irand( 0 , rule_num-1 );
      result = rules[rn].first * result * rules[rn].second;
    }
  }

  return result;
}
Example #20
0
void CMakeTool::fetchGeneratorsFromHelp() const
{
    Utils::SynchronousProcessResponse response = run({ "--help" });
    if (response.result != Utils::SynchronousProcessResponse::Finished)
        return;

    bool inGeneratorSection = false;
    QHash<QString, QStringList> generatorInfo;
    const QStringList lines = response.stdOut().split('\n');
    foreach (const QString &line, lines) {
        if (line.isEmpty())
            continue;
        if (line == "Generators") {
            inGeneratorSection = true;
            continue;
        }
        if (!inGeneratorSection)
            continue;

        if (line.startsWith("  ") && line.at(3) != ' ') {
            int pos = line.indexOf('=');
            if (pos < 0)
                pos = line.length();
            if (pos >= 0) {
                --pos;
                while (pos > 2 && line.at(pos).isSpace())
                    --pos;
            }
            if (pos > 2) {
                const QString fullName = line.mid(2, pos - 1);
                const int dashPos = fullName.indexOf(" - ");
                QString generator;
                QString extra;
                if (dashPos < 0) {
                    generator = fullName;
                } else {
                    extra = fullName.mid(0, dashPos);
                    generator = fullName.mid(dashPos + 3);
                }
                QStringList value = generatorInfo.value(generator);
                if (!extra.isEmpty())
                    value.append(extra);
                generatorInfo.insert(generator, value);
            }
        }
    }

    // Populate genertor list:
    for (auto it = generatorInfo.constBegin(); it != generatorInfo.constEnd(); ++it)
        m_generators.append(Generator(it.key(), it.value()));
}
Example #21
0
void MovementHolder::Mutate(MovementType moveType)
{
    // Funkce mutate slouzi k nastaveni generatoru cesty "na jistotu"
    // nebo k implicitnimu nastaveni

    if (moveType >= MOVEMENT_MAX)
        return;

    m_moveType = moveType;
    Generator();

    // Zmenime animaci modelu - je treba presunout asi, tady se mi to nelibi
    if (sAnimator->GetAnimId(m_src->pRecord->AnimTicket) != ANIM_WALK)
        sAnimator->ChangeModelAnim(m_src->pRecord->AnimTicket, ANIM_WALK, 0, 5);
}
Example #22
0
AbelianGroup MalcevSet::mapToQuotient(int k) const {

  if( ! isBasis )
    error("MalcevSet::mapToQuotient: the set must be full");

  // The generators of the quotient are basic commutators of weight k.

  const BasicCommutators& bc = theCollector.commutators();

  int numGen = bc.numberOfWeight(k);
  int firstGen = bc.theFirstOfWeight(k) - 1;

  // The relators are Malcev basis words of weight k

  SetOf<Word> relsForAbelian;

  QuickAssociationsIterator< Generator, PolyWord > iter(theSet);
  for( ; ! iter.done(); iter.next() ) {

    // take a word from Malcev basis

    PolyWord pw = iter.value();
    Letter first = pw.firstLetter();
    if( ord(first.gen) != firstGen ) continue; 
    
    //Ok, this is a word from the quotient. Abelianize it.

    ConstPolyWordIterator iter( pw );
    Word w;
    for(iter.startFromLeft(); ! iter.done(); iter.stepRight() ) {

      Letter s = iter.thisLetter();
      int newgen =  ord(s.gen) - firstGen;
      if( newgen > numGen ) break;
      s.gen = Generator( newgen );
      w *= Word(s);
    }
    relsForAbelian.adjoinElement(w);
  }

  // make the abelian quotient
  
  AbelianGroup abel( FPGroup(numGen, relsForAbelian) );
  abel.computeCyclicDecomposition();
  return abel;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
std::vector<int> GenerateLandingSpots(
  const int NumberOfLandingSpots,
  const int WindowWidth)
{
  std::vector<int> LandingSpots;
  std::default_random_engine Generator(
    std::chrono::high_resolution_clock::now().time_since_epoch().count());
  std::uniform_int_distribution<int> Distribution(0, WindowWidth - 8);

  auto Random = [&] { LandingSpots.emplace_back(Distribution(Generator)); };

  for (int i = 0; i < NumberOfLandingSpots; ++i)
  {
    Random();
  }
  return LandingSpots;
}
JNIEXPORT jint JNICALL Java_com_aliyun_icon_IconGenerator_generator(JNIEnv *env,
		jobject thiz, jintArray input, jintArray parameters, jintArray output) {
	pthread_mutex_lock(&lock);
	sprintf(showBuffer, "icon!!!!");
	__android_log_write(ANDROID_LOG_DEBUG, "icongenerator", showBuffer);

	int *smallIconInt = (int*) (env->GetIntArrayElements(input, 0));
	int *paras = (int*) (env->GetIntArrayElements(parameters, 0));
	int *bigIconInt = (int*) (env->GetIntArrayElements(output, 0));

	unsigned char *smallIconUC = (unsigned char *) smallIconInt;
	unsigned char *bigIconUC = (unsigned char *) bigIconInt;

	gettimeofday(&start, NULL);
	Generator(smallIconUC, paras, bigIconUC);
	gettimeofday(&end, NULL);
	timeuse = 1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec
			- start.tv_usec;
	timeuse /= 1000000;
	sprintf(showBuffer, "icontime ------------------  %f ", timeuse * 1000);
	__android_log_write(ANDROID_LOG_DEBUG, "icongenerator", showBuffer);

	sprintf(showBuffer, "pro finish!");
	__android_log_write(ANDROID_LOG_DEBUG, "icongenerator", showBuffer);

	env->ReleaseIntArrayElements(input, smallIconInt, 0);
	sprintf(showBuffer, "release 1 ok!");
	__android_log_write(ANDROID_LOG_DEBUG, "icongenerator", showBuffer);

	env->ReleaseIntArrayElements(output, bigIconInt, 0);

	sprintf(showBuffer, "release 2 ok!");
	__android_log_write(ANDROID_LOG_DEBUG, "icongenerator", showBuffer);

	env->ReleaseIntArrayElements(parameters, paras, 0);

	sprintf(showBuffer, "release ok!");
	__android_log_write(ANDROID_LOG_DEBUG, "icongenerator", showBuffer);

	pthread_mutex_unlock(&lock);

	return 1;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
sf::VertexArray GenerateLunarSurface(
  const unsigned WindowWidth,
  const unsigned WindowHeight)
{
  sf::VertexArray Lines(sf::LinesStrip, 0);

  auto LandingSpots = GenerateLandingSpots(4, WindowWidth);

  std::default_random_engine Generator(
    std::chrono::high_resolution_clock::now().time_since_epoch().count());
  std::uniform_int_distribution<int> Distribution(0, 1);
  auto Random = [&Generator, &Distribution] { return Distribution(Generator); };

  auto InLandingSpot = [&LandingSpots] (const int Width)
  {
    return std::any_of(
      LandingSpots.begin(),
      LandingSpots.end(),
      [Width] (int Value) { return Width >= Value && Width < Value + 40;});
  };

  auto Height = WindowHeight * .75;
  for (auto Width = 0u; Width < WindowWidth; Width += 4)
  {
    if (!InLandingSpot(Width))
    {
      if (Random())
      {
        Height += 18;
      }
      else
      {
        Height -= 18;
      }
      if (Height <= 0)
      {
        Height = 1;
      }
    }
    Lines.append(sf::Vector2f(Width, Height));
  }
  return Lines;
}
bool AbelianSGPresentationRep::fromSGGensToSGPGens(const Word& w,Word& wInNew) const
{
  int i, j, m, n;
  m = theSGPGens.height();
  n = theSGPGens.width();
  VectorOf<Integer> u(n);
  for(i=0; i<n; i++) u[i] = w.exponentSum(Generator(i+1));
  VectorOf<Integer> v(n);
  for(j=0; j<n; j++) {
    for(v[j]=i=0; i<n; i++) v[j] += u[i]*theSGPGensInv[i][j];
    if(j<m) {
      if(v[j]%theInvariants[j]==0) v[j] /= theInvariants[j];
      else return false;
    }
    else if(v[j]!=0) return false;
  }
  v.shrink(m);
  wInNew = AbelianWord(v).getWord();
  return true;
}
inline void EnumConverter<EnumT, Generator>::GetMaps(
	const std::unordered_set<const Record*, FmtHash, FmtHash>** byFmt,
	const std::unordered_set<const Record*, StrHash, StrHash>** byStr) 
{
	static std::vector<Record> records = Generator();

	static std::unordered_set<const Record*, FmtHash, FmtHash> byFmtData = [&] {
		std::unordered_set<const Record*, FmtHash, FmtHash> tmp;
		for (const auto& rec : records) {
			tmp.insert(&rec);
		}
		return tmp;
	}();
	static std::unordered_set<const Record*, StrHash, StrHash> byStrData = [&] {
		std::unordered_set<const Record*, StrHash, StrHash> tmp;
		for (const auto& rec : records) {
			tmp.insert(&rec);
		}
		return tmp;
	}();

	*byFmt = &byFmtData;
	*byStr = &byStrData;
}
Example #28
0
namespace flexiblesusy {

/**
 * @class Uniform
 * @brief real uniform distribution
 *
 * Usage:
 * @code
 * double x = Uniform<>::dice(0., 1.); // uses std::minstd_rand
 * double y = Uniform<std::mt19937>::dice(0., 1.); // uses std::mt19937
 * @endcode
 */
template <class Generator = std::minstd_rand>
class Uniform {
public:
   /// returns random number between start and stop
   static double dice(double start, double stop) {
      return start + (stop - start) * distribution(generator);
   }
   /// returns random number between 0. and 1.
   static double dice() {
      return distribution(generator);
   }
private:
   static Generator generator; ///< random number generator
   static std::uniform_real_distribution<double> distribution;
};

template <class Generator>
Generator Uniform<Generator>::generator = Generator();

template <class Generator>
std::uniform_real_distribution<double> Uniform<Generator>::distribution
   = std::uniform_real_distribution<double>(0., 1.);

} // namespace flexiblesusy
Example #29
0
TVerdict CEncryptStep::doTestStepPreambleL()
	{
	ConstructL();
	
	CTlsCryptoAttributes* atts = Provider()->Attributes();
	
	// Reads PSK values if included in INI file.
	ReadPskToBeUsedL();
	
	// Reads if NULL ciphers suites are to be allowed from INI file.
	ReadUseNullCipher();
	
	// read the "server" random
	HBufC8* random = ServerRandomL();
	atts->iMasterSecretInput.iServerRandom.Copy(*random);
	delete random;
	
	// and the client random
	random = ClientRandomL();
	atts->iMasterSecretInput.iClientRandom.Copy(*random);
	delete random;
	
	// we only support null compression...
	atts->iCompressionMethod = ENullCompression;
	
	// read the cipher suite for the test
	atts->iCurrentCipherSuite = CipherSuiteL();
	
	// read the protocol version
	TTLSProtocolVersion version = ProtocolVersionL();
	atts->iNegotiatedProtocol = version;
	atts->iProposedProtocol = version;
	
	// set the session ID and "server" name (localhost)
	atts->iSessionNameAndID.iSessionId = SessionId();
	atts->iSessionNameAndID.iServerName.iAddress = KLocalHost; 
	atts->iSessionNameAndID.iServerName.iPort = 443;
	atts->idomainName.Copy(DomainNameL());
	
	// If cipher suite under test is uses PSK (Pre Shared Key)
	if(UsePsk())
		{
		// Populates values for PSK
		atts->iPskConfigured = true; 
		atts->iPublicKeyParams->iKeyType = EPsk;
		atts->iPublicKeyParams->iValue4 = PskIdentity();
		atts->iPublicKeyParams->iValue5 = PskKey();
		}
	else 
		{
		// If cipher suite under test is NOT PSK 
		TRAPD(err, ReadDHParamsL());
		if (err == KErrNone)
			{
			atts->iPublicKeyParams->iKeyType = EDHE;

			// The params are:
			// 1 - Prime
			// 2 - Generator
			// 3 - generator ^ random mod prime

			atts->iPublicKeyParams->iValue1 = Prime().BufferLC();
			CleanupStack::Pop(atts->iPublicKeyParams->iValue1);

			atts->iPublicKeyParams->iValue2 = Generator().BufferLC();
			CleanupStack::Pop(atts->iPublicKeyParams->iValue2);

			atts->iPublicKeyParams->iValue3 = KeyPair()->PublicKey().X().BufferLC();
			CleanupStack::Pop(atts->iPublicKeyParams->iValue3);

			}
		}

	// No client authentication or dialogs for this test, please
	atts->iClientAuthenticate = EFalse;
	atts->iDialogNonAttendedMode = ETrue;
	
	if(UseNullCipher())
		{
		// Enables null cipher by setting appropiate parameter  
		atts->iAllowNullCipherSuites = ETrue;
 		}
	
	return EPass;
	}
Example #30
0
IMPDOMINO_BEGIN_NAMESPACE
RestraintCache::RestraintCache(ParticleStatesTable *pst, unsigned int size)
    : Object("RestraintCache%1%"),
      cache_(Generator(pst), size, ApproximatelyEqual()) {
  next_index_ = 0;
}