本文整理汇总了C++中random_seed函数的典型用法代码示例。如果您正苦于以下问题:C++ random_seed函数的具体用法?C++ random_seed怎么用?C++ random_seed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random_seed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vector_random_area
Vector vector_random_area(Seed * seed, Vector const corners[2][2])
{
float u = random_seed(seed);
float v = random_seed(seed);
return vector_interpolate_bilinear(corners, u, v);
}
示例2: main
int
main ()
{
random_t* random1Ptr;
random_t* random2Ptr;
random_t* random3Ptr;
long i;
puts("Starting...");
random1Ptr = random_alloc();
random2Ptr = random_alloc();
random3Ptr = random_alloc();
random_seed(random2Ptr, (RANDOM_DEFAULT_SEED + 1));
random_seed(random3Ptr, (RANDOM_DEFAULT_SEED + 1));
for (i = 0; i < NUM_ITERATIONS; i++) {
unsigned long rand1 = random_generate(random1Ptr);
unsigned long rand2 = random_generate(random2Ptr);
unsigned long rand3 = random_generate(random3Ptr);
printf("i = %2li, rand1 = %12lu, rand2 = %12lu, rand2 = %12lu\n",
i, rand1, rand2, rand3);
assert(rand1 != rand2);
assert(rand2 == rand3);
}
random_free(random1Ptr);
random_free(random2Ptr);
puts("Done.");
return 0;
}
示例3: tester
static void
tester (long geneLength, long segmentLength, long minNumSegment, bool_t doPrint)
{
gene_t* genePtr;
segments_t* segmentsPtr;
random_t* randomPtr;
bitmap_t* startBitmapPtr;
long i;
long j;
genePtr = gene_alloc(geneLength);
segmentsPtr = segments_alloc(segmentLength, minNumSegment);
randomPtr = random_alloc();
startBitmapPtr = bitmap_alloc(geneLength);
random_seed(randomPtr, 0);
gene_create(genePtr, randomPtr);
random_seed(randomPtr, 0);
segments_create(segmentsPtr, genePtr, randomPtr);
assert(segmentsPtr->minNum == minNumSegment);
assert(vector_getSize(segmentsPtr->contentsPtr) >= minNumSegment);
if (doPrint) {
printf("Gene = %s\n", genePtr->contents);
}
/* Check that each segment occurs in gene */
for (i = 0; i < vector_getSize(segmentsPtr->contentsPtr); i++) {
char *charPtr = strstr(genePtr->contents,
(char*)vector_at(segmentsPtr->contentsPtr, i));
assert(charPtr != NULL);
j = charPtr - genePtr->contents;
bitmap_set(startBitmapPtr, j);
if (doPrint) {
printf("Segment %li (@%li) = %s\n",
i, j, (char*)vector_at(segmentsPtr->contentsPtr, i));
}
}
/* Check that there is complete overlap */
assert(bitmap_isSet(startBitmapPtr, 0));
for (i = 0, j = 0; i < geneLength; i++ ) {
if (bitmap_isSet(startBitmapPtr, i)) {
assert((i-j-1) < segmentLength);
j = i;
}
}
gene_free(genePtr);
segments_free(segmentsPtr);
random_free(randomPtr);
bitmap_free(startBitmapPtr);
}
示例4: rgb_timing
void rgb_timing(Test **test, Rgb_Timing *timing)
{
double total_time,avg_time;
int i,j;
unsigned int *rand_uint;
MYDEBUG(D_RGB_TIMING){
printf("# Entering rgb_timing(): ps = %u ts = %u\n",test[0]->psamples,test[0]->tsamples);
}
seed = random_seed();
gsl_rng_set(rng,seed);
rand_uint = (uint *)malloc((size_t)test[0]->tsamples*sizeof(uint));
total_time = 0.0;
for(i=0;i<test[0]->psamples;i++){
start_timing();
for(j=0;j<test[0]->tsamples;j++){
rand_uint[j] = gsl_rng_get(rng);
}
stop_timing();
total_time += delta_timing();
}
avg_time = total_time/(test[0]->psamples*test[0]->tsamples);
timing->avg_time_nsec = avg_time*1.0e+9;
timing->rands_per_sec = 1.0/avg_time;
free(rand_uint);
}
示例5: EventLoop
/**********************************************************************
* Function: EventLoop
* Description: this is the main event loop for the program. It
* listens for events for .5 seconds, if none come in, it checks
* wheter it should timeout and lock the program. If the unit
* is scheduled to sleep within the next five seconds, it locks
* the display.
* Note: timeout does not work properly if you overclock you
* palm's processor.
* ********************************************************************/
static void
EventLoop (void)
{
EventType event;
UInt16 error;
do
{
// wait a bit for an event
EvtGetEvent (&event, 50);
/* Dont seed with empty events!*/
if(event.eType != nilEvent)
random_seed((byte *) &event, sizeof(event));
// first the system gets the event, then the Menu event handler, then the application
// event handler, then finally the form event handler
if (!SysHandleEvent (&event))
if (!MenuHandleEvent (0, &event, &error))
if (!ApplicationHandleEvent (&event))
FrmDispatchEvent (&event);
}
while (event.eType != appStopEvent);
}
示例6: gsl_rng_env_setup
void cHamiltonianMatrix::randomPotential(gsl_vector* randV){
const gsl_rng_type * T;
gsl_rng * r;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
// gsl_rng_env_setup() is getting a generator type and seed from environment variables.
// http://stackoverflow.com/questions/9768519/gsl-uniform-random-number-generator
// dev/random solution is very time consuming compared to the gettimeofday(),
// the gettimeofday() solution, might be better its level of accuracy is enough:
unsigned long int seed_number;
if (rank == 0) {
// seed_number = 0; // debug purpose.
seed_number = random_seed();
// cout << "Before broadcasting, seed number is " << seed_number << endl;
}
MPI_Bcast(&seed_number, 1, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); //replace MPI_INT by MPI_UNSIGNED_LONG if int is not long enough.
// cout << "After broadcasting, rank " << rank << " has seed number " << seed_number << endl;
gsl_rng_set(r,seed_number);
// gsl_rng_set(r,random_seed_devrandom());
for (int i = 0; i < L; i++)
{
gsl_vector_set(randV, i, -W/2+W*gsl_rng_uniform (r));
// gsl_vector_set(randV,i,1+i-double(L)/2.0);// non-disordered potential for benchmark
}
gsl_rng_free (r);
}
示例7: random_init
void random_init(void) {
// Initialize the memory of the random variables
memset(&random_vars, 0, sizeof(random_vars_t));
// Initialize the shift register
random_vars.shift_reg = random_seed();
}
示例8: init
int init(int nprt,int ndim,double *box,
double **pxyz,double **pvel,double **pacc)
{
/* allocate & initialize particles */
int i,k;
double x;
double *xyz=NULL;
double *vel=NULL;
double *acc=NULL;
/* allocate */
xyz=(double*)malloc(ndim*nprt*sizeof(double));
vel=(double*)malloc(ndim*nprt*sizeof(double));
acc=(double*)malloc(ndim*nprt*sizeof(double));
if( !xyz || !vel || !acc ) return 1;
/* init */
random_seed(1);
for(i=0; i<nprt; i++) {
for(k=0; k<ndim; k++) {
x=random_number();
xyz[i*ndim+k]=x * (box[2*k+1]-box[2*k]) + box[2*k];
}
}
/* update pointers */
*(pxyz)=xyz;
*(pvel)=vel;
*(pacc)=acc;
return 0;
}
示例9: main
void main() {
video_mode = 9;
max_entities = 30000;
terrain_chunk = 0;
level_load(NULL);
random_seed(0);
mouse_mode = 4;
vec_set(camera.x, vector(-1101, -97, 800));
vec_set(camera.pan, vector(4,-29,0));
// Terrain
BMAP* bmapHeightMap = generate_random_heightmap_noise(256, 256, 64);
BMAP* bmapColorMap = heightmap_to_colormap(bmapHeightMap);
ENTITY* entTerrain = terrain_from_heightmap(vector(0,0,-300), bmapHeightMap, 65, 65, 30, 0.4);
ent_setskin(entTerrain, bmapColorMap, 2);
entTerrain.material = mat_terrain_multi_texture;
// Roads
proc_city_create_skins();
List *points = roadnetwork_from_rectlangle(entTerrain.min_x + 100, entTerrain.min_y + 100, entTerrain.max_x - 50, entTerrain.max_y - 50, 200, 6);
//List *points = roadnetwork_from_voronoi(30, entTerrain.min_x + 100, entTerrain.min_y + 100, entTerrain.max_x - 50, entTerrain.max_y - 50);
List *intersections = roadnetwork_calculate(points);
roadnetwork_join_near_intersections(intersections, 100); // Delete intersections which are too near to each other
List *roadNetwork = roadnetwork_build(intersections, 300, true);
// Parcels
create_parcels(roadNetwork);
}
示例10: main
int main(int argc,char *argv[]) {
double x,y,pi;
int n_trials,i_trial,n_hits;
if (argc != 3) {
fprintf(stderr,"%s <N trials> <seed>\n",argv[0]);
exit(1);
}
n_trials = atoi(argv[1]);
random_seed(atoi(argv[2]));
i_trial = 0;
n_hits = 0;
while (i_trial < n_trials) {
/*
Add statements here to generate two random coordinates
within the square in the double precision variables x and y,
and increment the integer variable n_hits if x and y
represent a point within the unit circle
Hint: save computation time by NOT calling the sqrt() function!
*/
x = 2.0*(random_gen() - 0.5);
y = 2.0*(random_gen() - 0.5);
if (x*x + y*y <= 1) n_hits++;
i_trial++;
}
pi = 4.0 * ((double) n_hits) / ((double) n_trials);
printf("%.8f\n",pi);
exit(0);
}
示例11: client_alloc
/* =============================================================================
* client_alloc
* -- Returns NULL on failure
* =============================================================================
*/
client_t*
client_alloc (long id,
manager_t* managerPtr,
long numOperation,
long numQueryPerTransaction,
long queryRange,
long percentUser)
{
client_t* clientPtr;
clientPtr = (client_t*)malloc(sizeof(client_t));
if (clientPtr == NULL) {
return NULL;
}
clientPtr->randomPtr = random_alloc();
if (clientPtr->randomPtr == NULL) {
return NULL;
}
clientPtr->id = id;
clientPtr->managerPtr = managerPtr;
random_seed(clientPtr->randomPtr, id);
clientPtr->numOperation = numOperation;
clientPtr->numQueryPerTransaction = numQueryPerTransaction;
clientPtr->queryRange = queryRange;
clientPtr->percentUser = percentUser;
return clientPtr;
}
示例12: ebox_init
void ebox_init(void)
{
get_system_clock(&cpu.clock);
get_chip_info();
cpu.company[0] = 'S';
cpu.company[1] = 'T';
cpu.company[2] = '\0';
SysTick_Config(cpu.clock.core/1000);// 每隔 1ms产生一次中断
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);//systemticks clock;
micro_para = cpu.clock.core/1000000;//减少micros函数计算量
//统计cpu计算能力//////////////////
cpu.ability = 0;
millis_seconds = 0;
do
{
cpu.ability++;//统计cpu计算能力
}
while(millis_seconds < 100);
cpu.ability = cpu.ability * 10;
////////////////////////////////
ADC1_init();
NVIC_PriorityGroupConfig(NVIC_GROUP_CONFIG);
//将pb4默认设置为IO口,禁用jtag
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
set_systick_user_event_per_sec(1000);
random_seed(AD_value[0]);//初始化随机数种子
}
示例13: main
int
main ()
{
gene_t* gene1Ptr;
gene_t* gene2Ptr;
gene_t* gene3Ptr;
random_t* randomPtr;
bool_t status = memory_init(1, 4, 2);
assert(status);
puts("Starting...");
gene1Ptr = gene_alloc(10);
gene2Ptr = gene_alloc(10);
gene3Ptr = gene_alloc(9);
randomPtr = random_alloc();
random_seed(randomPtr, 0);
gene_create(gene1Ptr, randomPtr);
random_seed(randomPtr, 1);
gene_create(gene2Ptr, randomPtr);
random_seed(randomPtr, 0);
gene_create(gene3Ptr, randomPtr);
assert(gene1Ptr->length == strlen(gene1Ptr->contents));
assert(gene2Ptr->length == strlen(gene2Ptr->contents));
assert(gene3Ptr->length == strlen(gene3Ptr->contents));
assert(gene1Ptr->length == gene2Ptr->length);
assert(strcmp(gene1Ptr->contents, gene2Ptr->contents) != 0);
assert(gene1Ptr->length == (gene3Ptr->length + 1));
assert(strcmp(gene1Ptr->contents, gene3Ptr->contents) != 0);
assert(strncmp(gene1Ptr->contents,
gene3Ptr->contents,
gene3Ptr->length) == 0);
gene_free(gene1Ptr);
gene_free(gene2Ptr);
gene_free(gene3Ptr);
random_free(randomPtr);
puts("All tests passed.");
return 0;
}
示例14: main
int main(int argc, char **argv)
{
int i; /* Runs. */
population *pop=NULL; /* Population of solutions. */
char *beststring=NULL; /* Human readable form of best solution. */
size_t beststrlen=0; /* Length of beststring. */
for (i=0; i<50; i++)
{
if (pop) ga_extinction(pop);
random_seed(424242*i);
pop = ga_genesis_integer(
50, /* const int population_size */
1, /* const int num_chromo */
25, /* const int len_chromo */
NULL, /*pingpong_ga_callback,*/ /* GAgeneration_hook generation_hook */
NULL, /* GAiteration_hook iteration_hook */
NULL, /* GAdata_destructor data_destructor */
NULL, /* GAdata_ref_incrementor data_ref_incrementor */
pingpong_score, /* GAevaluate evaluate */
pingpong_seed, /* GAseed seed */
NULL, /* GAadapt adapt */
ga_select_one_randomrank, /* GAselect_one select_one */
ga_select_two_randomrank, /* GAselect_two select_two */
pingpong_mutate, /* GAmutate mutate */
pingpong_crossover, /* GAcrossover crossover */
NULL, /* GAreplace replace */
NULL /* vpointer User data */
);
ga_population_set_parameters(
pop, /* population *pop */
GA_SCHEME_DARWIN, /* const ga_scheme_type scheme */
GA_ELITISM_PARENTS_SURVIVE, /* const ga_elitism_type elitism */
0.5, /* double crossover */
0.5, /* double mutation */
0.0 /* double migration */
);
ga_evolution(
pop, /* population *pop */
200 /* const int max_generations */
);
pingpong_ga_callback(i, pop);
}
printf("The final solution found was:\n");
beststring = ga_chromosome_integer_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen);
printf("%s\n", beststring);
ga_extinction(pop);
s_free(beststring);
exit(EXIT_SUCCESS);
}
示例15: main
int main(int argc, char **argv)
{
population *pop=NULL; /* Population structure. */
char *beststring=NULL; /* Human readable form of best solution. */
size_t beststrlen=0; /* Length of beststring. */
random_seed(23091975);
pop = ga_genesis_char(
120, /* const int population_size */
1, /* const int num_chromo */
(int) strlen(target_text), /* const int len_chromo */
struggle_generation_hook, /* GAgeneration_hook generation_hook */
NULL, /* GAiteration_hook iteration_hook */
NULL, /* GAdata_destructor data_destructor */
NULL, /* GAdata_ref_incrementor data_ref_incrementor */
struggle_score, /* GAevaluate evaluate */
ga_seed_printable_random, /* GAseed seed */
struggle_adaptation, /* GAadapt adapt */
ga_select_one_sus, /* GAselect_one select_one */
ga_select_two_sus, /* GAselect_two select_two */
ga_mutate_printable_singlepoint_drift, /* GAmutate mutate */
ga_crossover_char_allele_mixing, /* GAcrossover crossover */
NULL, /* GAreplace replace */
NULL /* vpointer User data */
);
ga_population_set_parameters(
pop, /* population *pop */
GA_SCHEME_LAMARCK_CHILDREN, /* const ga_scheme_type scheme */
GA_ELITISM_PARENTS_DIE, /* const ga_elitism_type elitism */
0.8, /* const double crossover */
0.05, /* const double mutation */
0.0 /* const double migration */
);
if ( ga_evolution( pop, 1000 )<1000 )
{
printf("The evolution was stopped because the termination criteria were met.\n" );
}
else
{
printf("The evolution was stopped because the maximum number of generations were performed.\n" );
}
printf( "The final solution with score %f was:\n",
ga_get_entity_from_rank(pop,0)->fitness );
beststring = ga_chromosome_char_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen);
printf("%s\n", beststring);
printf( "Total number of fitness evaluations: %ld\n", evaluation_count );
ga_extinction(pop);
s_free(beststring);
exit(EXIT_SUCCESS);
}