int main( )
{
    // Use Boost library to make a random number generator.
    boost::mt19937 randomNumbergenerator( time( 0 ) );
    boost::random::uniform_real_distribution< > uniformDistribution( 0.0, 10.0 );
    boost::variate_generator< boost::mt19937&, boost::random::uniform_real_distribution < > >
            generateRandomNumbers( randomNumbergenerator, uniformDistribution );

    // Generate random altitude value between 0 and 10 km.
    const double altitudeKilometers = generateRandomNumbers( );

    // Use the Tudat Core library to convert km to m.
    const double altitudeMeters = tudat::unit_conversions::convertKilometersToMeters(
            altitudeKilometers );

    // Use the Eigen library to create position vectors.
    Eigen::Vector3d positionOfBodySubjectToAcceleration;
    positionOfBodySubjectToAcceleration << 1737.1e3 + altitudeMeters, 0.0, 0.0;
    const Eigen::Vector3d positionOfBodyExertingAcceleration = Eigen::Vector3d::Zero( );

    // Use the Tudat library to compute the acceleration vector.
    const Eigen::Vector3d gravitationalAcceleration =
            tudat::gravitation::computeGravitationalAcceleration(
                    positionOfBodySubjectToAcceleration, 4.9e12,
                    positionOfBodyExertingAcceleration );

    // Print the altitude and norm of the acceleration vector.
    std::cout << "Hello world!" << std::endl;
    std::cout << "I am floating " << altitudeKilometers << " km above the Moon's surface." <<
            std::endl;
    std::cout << "The gravitational acceleration here is " <<
            gravitationalAcceleration.norm() << " m/s^2."  << std::endl;

    return 0;
}
예제 #2
0
bool getRandomRtspSource(std::map<std::string, std::string>& randRtspScource)
{
	std::map<std::string, std::string> totalRtspSource;
	if (!extractRtspSource(totalRtspSource)) return false;
	int recordNumberEachTime = -1;
	if (!extractRecordNumberEachTime(recordNumberEachTime)) return false;

	int min = 0, max = totalRtspSource.size();
	std::vector<int> randNumbers;
	if (!generateRandomNumbers(recordNumberEachTime, min, max, randNumbers)) {
			return false;
	}
	std::sort(randNumbers.begin(), randNumbers.end());

	std::map<std::string, std::string>::iterator it = totalRtspSource.begin();
	for (int i = 0; it != totalRtspSource.end(); it++, i++) {
		std::size_t j = 0;
		for (; j < randNumbers.size(); ++j) {
			if (i == randNumbers[j]) break;
		}
		if (j != randNumbers.size()) {
			randRtspScource.insert(*it);
		}
	}
	return true;
}
예제 #3
0
double NormalGenerator::get() {

    if(randLeft) {
        randLeft = false;
        return lastNumber;
    } else {
        return generateRandomNumbers();
    }
}
void main()
{
    int i;
    int value;
    int position;
    setHashMatrixNull();
    generateRandomNumbers();
    insertAll();
    printHashMatrix();
    printf("Enter the desired value or -1 to exit\n");

    while( value!= -1 )
    {
        scanf("%d", &value);
        if(value != -1)
        {
            position = findValue(value);
            if(position > -1)
            {
                printf("value stored on position %d \n", position);
            }
        }
    }
}
예제 #5
0
int main(int argc, char **argv)
{
    long long numRands = 0;
    long long numRandsPerNode = 0;      
	long long totNums = 0;
	long long count;
	char hostname[MAXHOSTNAMELEN];

    double timeStart = 0;
    double timeElapsed = 0;
	MPI_Status status;

	int i;
    int nproc;
	int remainder;
	int me;
	int who;
	const int JOB_COMPLETED = 1;

  	if (argc < 2) {
        fprintf(stderr, "Usage: %s <n>\n" ,argv[0]);
        exit(1);
    }
    sscanf(argv[1],"%lld",&numRands); /* lld for long long int */

  	/* Start up MPI */
  	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &nproc);
	MPI_Comm_rank(MPI_COMM_WORLD, &me);

	gethostname(hostname, MAXHOSTNAMELEN);

	printf("Hello! I am %d of %d running on %s.\n", me, nproc, hostname);


	numRandsPerNode = numRands/nproc;
	remainder = numRands % nproc;
	/* divide remainder  numbers into remainder processes */
	if (me == nproc -1) {
		numRandsPerNode += remainder;
	}


	if (me == 0) {
    	timeStart = MPI_Wtime(); /* and we are off! */
	}
    generateRandomNumbers(me, numRandsPerNode);
#ifdef DEBUG
	printf("Process %d generated %lld random numbers\n", me, numRandsPerNode);
#endif

	if (me == 0) {
		printf("Process %d generated %lld random numbers\n", me, numRandsPerNode);
   		/* Wait for acknowledgemnt from process 1 ..nproc-1 */ 
    	for (i=1; i<nproc; i++) {
			MPI_Recv(&count, 1, MPI_LONG_LONG_INT, MPI_ANY_SOURCE, JOB_COMPLETED, MPI_COMM_WORLD, &status);
            who = status.MPI_SOURCE;
        	totNums += count;                 //Added to the results so far
			printf("Received message from process %d (generated %lld numbers)\n", who, count);
    	}
	} else {
     /* Send acknowledgemnt to process 0 of job completed */  
	 	MPI_Send(&numRandsPerNode, 1, MPI_LONG_LONG_INT, 0, JOB_COMPLETED, MPI_COMM_WORLD);
	}

	if (me == 0) {
    	timeElapsed = MPI_Wtime() - timeStart;
    	printf("Elapsed time:  %lf seconds\n",timeElapsed);
    	fflush(stdout);
	}

  	MPI_Finalize();
    exit(0);
}