namespace math { // Set the random numbers sequence seed with the current system time, so that it is always different unsigned int static set_random_seed() { unsigned int seed = static_cast<unsigned int>(time(NULL)); srand(seed); return seed; } const float PI = 3.14159265f; unsigned int seed = set_random_seed(); int rand(int begin, int end) { return std::rand() % (end - begin + 1) + begin; } float rand(float begin, float end) { return static_cast<float>(std::rand()) / RAND_MAX * (end - begin) + begin; } void set_seed(unsigned int s) { srand(s); seed = s; } }
void unit_test_jit_fragment_tree() { uint i; bb_node_t *node_list[FRAGMENT_TREE_TEST_NODE_COUNT]; /* N.B.: may contain NULLs */ print_file(STDERR, "test DGC fragment tree: "); dynamo_options.opt_jit = true; fragment_tree = fragment_tree_create(); set_random_seed((uint) query_time_millis()); for (i = 0; i < 3; i++) { print_file(STDERR, "pass %d... ", i+1); unit_test_insert_random_nodes(node_list, FRAGMENT_TREE_TEST_NODE_COUNT); unit_test_remove_random_spans(node_list, FRAGMENT_TREE_TEST_NODE_COUNT); fragment_tree_clear(fragment_tree); unit_test_churn_narrow_span(node_list, FRAGMENT_TREE_TEST_NODE_COUNT); fragment_tree_clear(fragment_tree); } fragment_tree_destroy(fragment_tree); print_file(STDERR, "\n"); }
static void init_rand(void) { if (!rand_inited) { #ifdef HAVE_LIBGSL if (rng) gsl_rng_free(rng); rng = gsl_rng_alloc(gsl_rng_mt19937); #endif rand_inited = true; // no infinite loop since rand_inited == true set_random_seed(time(NULL) * (1 + my_global_rank())); } }
void CGenNodeStateless::refresh_vm_bss(){ if ( m_vm_flow_var ) { StreamVmDp * vm_s=m_ref_stream_info->m_vm_dp; assert(vm_s); memcpy(m_vm_flow_var,vm_s->get_bss(),vm_s->get_bss_size()); if ( vm_s->is_random_seed() ){ /* if we have random seed for this program */ if (m_ref_stream_info->m_random_seed) { set_random_seed(m_ref_stream_info->m_random_seed); } } } }
static bool unit_test_insert_random_node(bb_node_t **node_list, app_pc random_base, uint random_span, uint index) { app_pc random_start = unit_test_get_random_pc(random_base, random_span); app_pc random_end = unit_test_get_random_pc(random_start + 2, 0x40); if (fragment_tree_lookup(fragment_tree, random_start, random_end) == NULL) { node_list[index] = fragment_tree_insert(fragment_tree, random_start, random_end); return true; } else { set_random_seed((uint) query_time_millis()); return false; } }
void CGenNodeStateless::generate_random_seed() { /* seed can be provided by the user */ uint32_t unique_seed; if (m_ref_stream_info->m_random_seed) { unique_seed = m_ref_stream_info->m_random_seed; } else { unsigned int tmp = (unsigned int)time(NULL); unique_seed = rand_r(&tmp); } /* per thread divergence */ unique_seed = (unique_seed * ( (m_thread_id + 1) * 514229 ) ) & 0xFFFFFFFF; /* set random */ set_random_seed(unique_seed); }
int main(int argc, char *argv[]) { int i; char buffer[1000]; struct mtwist_state *mt; set_random_seed(&mt); for (i = 0; i < 1000; i++) { /* infinite_taunt(buffer, sizeof(buffer) - 1); */ /* planet_description(mt, buffer, sizeof(buffer) - 1, 60); */ cop_attack_warning(mt, buffer, sizeof(buffer) - 1, 50); printf("%s\n", buffer); } free(mt); return 0; }
static void check_initialized( void ) { #if HAVE_GETTIMEOFDAY struct timeval t; #endif int seed; if( !initialized ) { #if HAVE_GETTIMEOFDAY (void) gettimeofday( &t, (struct timezone *) 0 ); seed = (int) t.tv_usec; #else seed = time(NULL); #endif set_random_seed( seed ); } }
//run by next thread for every command void * execute_command(void * args){ char op[MAX_ARG_LEN]; int a1, a2, a3, retval; int * arg1, * arg2, * arg3; arg1 = &a1; arg2 = &a2; arg3 = &a3; *arg1 = 0; *arg2 = 0; *arg3 = 0; char * command = ((arg_struct *)args)->command; int sender = ((arg_struct *)args)->sender; int timestamp = ((arg_struct *)args)->timestamp; set_random_seed(((arg_struct *)args)->random); sscanf(command, "%s ", op); if(strcmp(op, "delete") == 0){ if(sscanf(command+7, "%d ", arg1) != 1) printf("Delete requires a key\n"); else retval = op_jump_function(*arg1, 0, 0, timestamp, command, 3, 0, sender); } else if(strcmp(op, "get") == 0){ if(sscanf(command+4, "%d %d ", arg1, arg2) != 2) printf("Get requires a key and a level\n"); else retval = op_jump_function(*arg1, 0, *arg2, timestamp, command, 0, 0, sender); } else if(strcmp(op, "insert") == 0){ if(sscanf(command+7, "%d %d %d ", arg1, arg2, arg3) != 3) printf("Insert requires a key, value, and level\n"); else retval = op_jump_function(*arg1, *arg2, *arg3, timestamp, command, 1, 0, sender); } else if(strcmp(op, "update") == 0){ if(sscanf(command+7, "%d %d %d ", arg1, arg2, arg3) != 3) printf("Update requies a key, value, and level\n"); else retval = op_jump_function(*arg1, *arg2, *arg3, timestamp, command, 2, 0, sender); } else{ printf("Received unknown command %s\n", command); } free(command); return 0; }
int main(int argc, char* argv[]) { p1u_setup(); set_random_seed(get_my_student_id() + 3014); int endY = createWorld(); move_along_corridor(); P1U_ASSERT_EQUAL("Robot should be at X = 9", 9, get_current_robot_x()); char message[32]; sprintf(message, "Robot should be at Y = %d", endY); P1U_ASSERT_EQUAL(message, endY, get_current_robot_y()); P1U_ASSERT_EQUAL("Robot should be facing east", get_current_robot_orientation(), get_east()); P1U_ASSERT_FALSE("Robot should survive", is_robot_dead()); p1u_shutdown(); return (p1world_shutdown()); }
int main(int argc, char *argv[]) { const char *filename; FILE *input_FILE; const char *const *output_strings; int mode; int move_pos; char line[BUFSIZE]; char name[BUFSIZE]; char stones[BUFSIZE]; int value; char board[MAX_BOARD + 2][MAX_BOARD + 2]; Intersection board1d[BOARDSIZE]; int boardsize; int i, j, k; int pos; char color; /* Check number of arguments. */ if (argc != 4) { fprintf(stderr, USAGE); return EXIT_FAILURE; } boardsize = atoi(argv[1]); filename = argv[2]; if (strncmp(argv[3], "c", 2) == 0) { mode = C_OUTPUT; output_strings = c_output_strings; set_random_seed(HASH_RANDOM_SEED); hash_init(); } else if (strncmp(argv[3], "db", 3) == 0) { mode = DB_OUTPUT; output_strings = db_output_strings; } else { fprintf(stderr, USAGE); return EXIT_FAILURE; } assert(boardsize > 0); if (boardsize > MAX_BOARD) { printf(output_strings[PREAMBLE]); printf(output_strings[HEADER], boardsize); printf(output_strings[FOOTER]); return EXIT_SUCCESS; } input_FILE = fopen(filename, "r"); if (!input_FILE) { fprintf(stderr, "uncompress_fuseki: Cannot open file %s\n", filename); return EXIT_FAILURE; } /* Initialize the corners of the internal board description. */ board[0][0] = '+'; board[0][boardsize + 1] = '+'; board[boardsize + 1][0] = '+'; board[boardsize + 1][boardsize + 1] = '+'; /* Initialize the sides of the internal board description. */ for (k = 1; k <= boardsize; k++) { board[0][k] = '-'; board[boardsize + 1][k] = '-'; board[k][0] = '|'; board[k][boardsize + 1] = '|'; } printf(output_strings[PREAMBLE]); printf(output_strings[HEADER], boardsize); /* Loop over the lines of the compressed database. * Each line is one pattern. */ while (fgets(line, BUFSIZE, input_FILE)) { int num_stones = 0; /* Clear the internal board. */ for (i = 1; i <= boardsize; i++) for (j = 1; j <= boardsize; j++) board[i][j] = '.'; /* Initialize private 1D-board. */ for (pos = 0; pos < BOARDSIZE; pos++) if (I(pos) >= 0 && I(pos) < boardsize && J(pos) >= 0 && J(pos) < boardsize) board1d[pos] = EMPTY; else board1d[pos] = GRAY; /* Assume a line from copyright notice if misformed and * silently ignore it. */ if (sscanf(line, "%s %d %s", name, &value, stones) != 3) continue; /* The first point in the stones list is the move to be played. */ move_pos = set_boards(board, board1d, stones, '*', boardsize); /* Then follows alternating X and O stones. */ color = 'X'; for (k = 2; k < (int) strlen(stones); k += 2) { pos = set_boards(board, board1d, stones + k, color, boardsize); if (I(pos) >= 0 && I(pos) < boardsize && J(pos) >= 0 && J(pos) < boardsize) num_stones++; if (color == 'X') color = 'O'; else color = 'X'; } if (mode == DB_OUTPUT) write_pattern(name, board, value, boardsize); else write_pattern_c_code(name, board1d, move_pos, value, boardsize, num_stones); } /* Add a dummy pattern to mark the end of the array. This can't be * done statically in the footer since NUM_HASHVALUES may vary. */ if (mode == C_OUTPUT) write_pattern_c_code(NULL, board1d, NO_MOVE, 0, boardsize, -1); printf(output_strings[FOOTER]); return EXIT_SUCCESS; }
void *db_worker(void *data) { int id = *((int *) data); /* Whoa... */ struct transaction_queue_node_t *node; struct db_context_t *dbc; char code; double response_time; struct timeval rt0, rt1; int local_seed; pid_t pid; pthread_t tid; extern unsigned int seed; int status; /* Each thread needs to seed in Linux. */ tid = pthread_self(); pid = getpid(); if (seed == -1) { struct timeval tv; unsigned long junk; /* Purposely used uninitialized */ local_seed = pid; gettimeofday(&tv, NULL); local_seed ^= tid ^ tv.tv_sec ^ tv.tv_usec ^ junk; } else { local_seed = seed; } set_random_seed(local_seed); /* Open a connection to the database. */ dbc = db_init(); if (!exiting && connect_to_db(dbc) != OK) { LOG_ERROR_MESSAGE("connect_to_db() error, terminating program"); printf("cannot connect to database(see details in error.log file, exiting...\n"); exit(1); } while (!exiting) { /* * I know this loop will prevent the program from exiting * because of the dequeue... */ node = dequeue_transaction(); if (node == NULL) { LOG_ERROR_MESSAGE("dequeue was null"); continue; } /* Execute transaction and record the response time. */ if (gettimeofday(&rt0, NULL) == -1) { perror("gettimeofday"); } status = process_transaction(node->client_data.transaction, dbc, &node->client_data.transaction_data); if (status == ERROR) { LOG_ERROR_MESSAGE("process_transaction() error on %s", transaction_name[ node->client_data.transaction]); /* * Assume this isn't a fatal error, send the results * back, and try processing the next transaction. */ while (need_reconnect_to_db(dbc)) { LOG_ERROR_MESSAGE("try to reconnect to database"); disconnect_from_db(dbc); if (connect_to_db(dbc) != OK) { LOG_ERROR_MESSAGE("reconnect to database error, try again after sleep 5 seconds"); sleep(5); } } } if (status == OK) { code = 'C'; } else if (status == STATUS_ROLLBACK) { code = 'R'; } else if (status == ERROR) { code = 'E'; } if (gettimeofday(&rt1, NULL) == -1) { perror("gettimeofday"); } response_time = difftimeval(rt1, rt0); log_transaction_mix(node->client_data.transaction, code, response_time, mode_altered > 0 ? node->termworker_id : node->term_id); enqueue_terminal(node->termworker_id, node->term_id); /* Keep track of how many transactions this thread has done. */ ++worker_count[id]; /* Keep track of then the last transaction was execute. */ time(&last_txn[id]); } /* Disconnect from the database. */ disconnect_from_db(dbc); free(dbc); sem_wait(&db_worker_count); return NULL; /* keep compiler quiet */ }
void handle_common_deferred_options (void) { unsigned int i; cl_deferred_option *opt; vec<cl_deferred_option> v; if (common_deferred_options) v = *((vec<cl_deferred_option> *) common_deferred_options); else v = vNULL; if (flag_dump_all_passed) enable_rtl_dump_file (); if (flag_opt_info) opt_info_switch_p (NULL); FOR_EACH_VEC_ELT (v, i, opt) { switch (opt->opt_index) { case OPT_fcall_used_: fix_register (opt->arg, 0, 1); break; case OPT_fcall_saved_: fix_register (opt->arg, 0, 0); break; case OPT_fdbg_cnt_: dbg_cnt_process_opt (opt->arg); break; case OPT_fdbg_cnt_list: dbg_cnt_list_all_counters (); break; case OPT_fdebug_prefix_map_: add_debug_prefix_map (opt->arg); break; case OPT_fdump_: if (!g->get_dumps ()->dump_switch_p (opt->arg)) error ("unrecognized command line option %<-fdump-%s%>", opt->arg); break; case OPT_fopt_info_: if (!opt_info_switch_p (opt->arg)) error ("unrecognized command line option %<-fopt-info-%s%>", opt->arg); break; case OPT_fenable_: case OPT_fdisable_: if (opt->opt_index == OPT_fenable_) enable_pass (opt->arg); else disable_pass (opt->arg); break; case OPT_ffixed_: /* Deferred. */ fix_register (opt->arg, 1, 1); break; case OPT_fplugin_: #ifdef ENABLE_PLUGIN add_new_plugin (opt->arg); #else error ("plugin support is disabled; configure with --enable-plugin"); #endif break; case OPT_fplugin_arg_: #ifdef ENABLE_PLUGIN parse_plugin_arg_opt (opt->arg); #else error ("plugin support is disabled; configure with --enable-plugin"); #endif break; case OPT_frandom_seed: /* The real switch is -fno-random-seed. */ if (!opt->value) set_random_seed (NULL); break; case OPT_frandom_seed_: set_random_seed (opt->arg); break; case OPT_fstack_limit: /* The real switch is -fno-stack-limit. */ if (!opt->value) stack_limit_rtx = NULL_RTX; break; case OPT_fstack_limit_register_: { int reg = decode_reg_name (opt->arg); if (reg < 0) error ("unrecognized register name %qs", opt->arg); else stack_limit_rtx = gen_rtx_REG (Pmode, reg); } break; case OPT_fstack_limit_symbol_: stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (opt->arg)); break; case OPT_fasan_shadow_offset_: if (!(flag_sanitize & SANITIZE_KERNEL_ADDRESS)) error ("-fasan-shadow-offset should only be used " "with -fsanitize=kernel-address"); if (!set_asan_shadow_offset (opt->arg)) error ("unrecognized shadow offset %qs", opt->arg); break; case OPT_fsanitize_sections_: set_sanitized_sections (opt->arg); break; default: gcc_unreachable (); } } }
lsb_lua_sandbox* lsb_create(void *parent, const char *lua_file, const char *cfg, lsb_logger logger) { if (!lua_file) { if (logger) logger(__FUNCTION__, 3, "lua_file must be specified"); return NULL; } if (!set_tz()) { if (logger) logger(__FUNCTION__, 3, "fail to set the TZ to UTC"); return NULL; } set_random_seed(); lsb_lua_sandbox *lsb = malloc(sizeof*lsb); if (!lsb) { if (logger) logger(__FUNCTION__, 3, "memory allocation failed"); return NULL; } memset(lsb->usage, 0, sizeof(lsb->usage)); #ifdef LUA_JIT lsb->lua = luaL_newstate(); #else lsb->lua = lua_newstate(memory_manager, lsb); #endif if (!lsb->lua) { if (logger) logger(__FUNCTION__, 3, "lua state creation failed"); free(lsb); return NULL; } // add the config to the lsb_config registry table lua_State *lua_cfg = load_sandbox_config(cfg, logger); if (!lua_cfg) { lua_close(lsb->lua); free(lsb); return NULL; } lua_pushnil(lua_cfg); lua_pushvalue(lua_cfg, LUA_GLOBALSINDEX); copy_table(lsb->lua, lua_cfg, logger); lua_pop(lua_cfg, 2); lua_close(lua_cfg); size_t ml = get_usage_config(lsb->lua, -1, "memory_limit"); size_t il = get_usage_config(lsb->lua, -1, "instruction_limit"); size_t ol = get_usage_config(lsb->lua, -1, "output_limit"); lua_setfield(lsb->lua, LUA_REGISTRYINDEX, LSB_CONFIG_TABLE); lua_pushcclosure(lsb->lua, &read_config, 0); lua_setglobal(lsb->lua, "read_config"); lua_pushlightuserdata(lsb->lua, (void *)lsb); lua_pushcclosure(lsb->lua, &output, 1); lua_setglobal(lsb->lua, "output"); lsb->parent = parent; lsb->usage[LSB_UT_MEMORY][LSB_US_LIMIT] = ml; lsb->usage[LSB_UT_INSTRUCTION][LSB_US_LIMIT] = il; lsb->usage[LSB_UT_OUTPUT][LSB_US_LIMIT] = ol; lsb->state = LSB_UNKNOWN; lsb->error_message[0] = 0; lsb->lua_file = malloc(strlen(lua_file) + 1); lsb->state_file = NULL; if (!lsb->lua_file || lsb_init_output_buffer(&lsb->output, ol)) { if (logger) logger(__FUNCTION__, 3, "memory allocation failed failed"); lsb_free_output_buffer(&lsb->output); free(lsb->lua_file); lua_close(lsb->lua); lsb->lua = NULL; free(lsb); return NULL; } strcpy(lsb->lua_file, lua_file); return lsb; }
//------- Begin of function Misc::randomize --------// // void Misc::randomize() { set_random_seed((long)time(NULL)); // Implicit conversion from time_t to float. }
int main(int argc, char *argv[]) { int result = ACTION_NONE; int leave = 0; /* i18n */ #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif /* ltris info */ printf( "LTris %s\nCopyright 2002-2005 Michael Speck\nPublished under GNU GPL\n---\n", VERSION ); printf( "Looking up data in: %s\n", SRC_DIR ); #ifndef SOUND printf( "Compiled without sound and music\n" ); #endif set_random_seed(); /* set random seed */ /* game ids - not translated to be fixed independant of language */ strcpy(gametype_ids[0],"demo"); strcpy(gametype_ids[1],"classic"); strcpy(gametype_ids[2],"figures"); strcpy(gametype_ids[3],"vshuman"); strcpy(gametype_ids[4],"vscpu"); strcpy(gametype_ids[5],"vshumanhuman"); strcpy(gametype_ids[6],"vshumancpu"); strcpy(gametype_ids[7],"vscpucpu"); /* game names - translated for display */ strcpy(gametype_names[0],_("Demo")); strcpy(gametype_names[1],_("Classic")); strcpy(gametype_names[2],_("Figures")); strcpy(gametype_names[3],_("Vs Human")); strcpy(gametype_names[4],_("Vs CPU")); strcpy(gametype_names[5],_("Vs Human&Human")); strcpy(gametype_names[6],_("Vs Human&CPU")); strcpy(gametype_names[7],_("Vs CPU&CPU")); config_load(); init_sdl( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER ); set_video_mode( std_video_mode( config.fullscreen ) ); SDL_WM_SetCaption( "LTris", 0 ); sdl.fade = config.fade; SDL_SetEventFilter( event_filter ); #ifdef SOUND audio_open(); sound_enable( config.sound ); sound_volume( config.volume * 16 ); #endif /* create */ hint_load_res(); manager_create(); tetris_create(); chart_load(); /* run game */ manager_fade( FADE_IN ); while( !leave && !term_game ) { result = manager_run(); switch( result ) { case ACTION_QUIT: leave = 1; break; case ACTION_MAKE_STAT: manager_fade( FADE_OUT ); tetris_make_stat(); manager_fade( FADE_IN ); break; case ACTION_PLAY: manager_fade( FADE_OUT ); if ( tetris_init() ) { tetris_run(); tetris_clear(); } manager_fade( FADE_IN ); break; default: break; } } manager_fade( FADE_OUT ); /* delete stuff */ tetris_delete(); manager_delete(); chart_save(); chart_delete(); hint_delete_res(); #ifdef SOUND audio_close(); #endif config_save(); return EXIT_SUCCESS; }
void Caffe::set_root_seed(uint64_t random_seed) { if (random_seed != Caffe::SEED_NOT_SET) { root_seed_.store(random_seed); set_random_seed(random_seed); } }
int main(int argc, char *argv[]) { int result = ACTION_NONE; int leave = 0; char *editor_file = 0; char path[512]; SDL_Surface *loading; #ifdef __unix__ gid_t realgid; hi_dir_chart_file = fopen(HI_DIR "/" CHART_FILE_NAME, "r+"); /* This is where we drop our setuid/setgid privileges. */ realgid = getgid(); if (setresgid(-1, realgid, realgid) != 0) { perror("Could not drop setgid privileges. Aborting."); exit(1); } #endif /* i18n */ #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif #ifdef _WIN32 /* Get Windows to open files in binary mode instead of default text mode */ _fmode = _O_BINARY; #endif /* lbreakout info */ printf( "LBreakout2 %s\nCopyright 2001-2010 Michael Speck\nPublished under GNU GPL\n---\n", VERSION ); printf( "Looking up data in: %s\n", SRC_DIR ); printf( "Looking up highscores in: %s\n", HI_DIR ); printf( "Looking up custom levels in: %s/%s/lbreakout2-levels\n", (getenv( "HOME" )?getenv( "HOME" ):"."), CONFIG_DIR_NAME ); #ifndef AUDIO_ENABLED printf( "Compiled without sound and music\n" ); #endif set_random_seed(); /* set random seed */ config_load(); stk_init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK ); if ( config.fullscreen ) stk_display_open( SDL_SWSURFACE | SDL_FULLSCREEN, 640, 480, 16 ); else stk_display_open( SDL_SWSURFACE, 640, 480, 16 ); stk_audio_open( 0,0,0,config.audio_buffer_size ); SDL_WM_SetCaption( "LBreakout2", 0 ); SDL_SetEventFilter( event_filter ); stk_audio_enable_sound( config.sound ); stk_audio_set_sound_volume( config.volume * 16 ); /* load a little loading pic */ stk_surface_set_path( SRC_DIR "/gfx" ); loading = stk_surface_load( SDL_SWSURFACE, "loading.png" ); stk_surface_blit( loading, 0,0,-1,-1, stk_display, (stk_display->w-loading->w)/2, (stk_display->h-loading->h)/2 ); stk_display_update( STK_UPDATE_ALL ); /* load the GUI graphics from SRC_DIR/gui_theme */ stk_surface_set_path( SRC_DIR ); stk_audio_set_path( SRC_DIR ); gui_init( "gui_theme" ); stk_surface_set_path( SRC_DIR "/gfx" ); stk_audio_set_path( SRC_DIR "/sounds" ); /* load resources */ /* for simplicity all functions are kept but anything * that is now themeable is loaded in * theme_load instead of the original function * (deleting resources works analouge) */ theme_get_list(); if ( config.theme_count != theme_count ) { if ( config.theme_id >= theme_count ) config.theme_id = 0; config.theme_count = theme_count; } theme_load( theme_names[config.theme_id] ); /* old functions still with initialzations of * lists or variables */ client_game_create(); hint_load_res(); chart_load(); manager_create(); client_create(); exp_load(); editor_create(); help_create(); /* run game */ manager_fade( STK_FADE_IN ); while( !leave && !stk_quit_request ) { result = manager_run(); switch( result ) { case ACTION_QUIT: leave = 1; break; case ACTION_RESUME_0: manager_fade( STK_FADE_OUT ); if ( client_game_resume_local( 0 ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_PLAY_LBR: manager_fade( STK_FADE_OUT ); gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */ if ( client_game_init_local( "LBreakout2" ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_PLAY_CUSTOM: manager_fade( STK_FADE_OUT ); gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */ if (gameSeed==0) gameSeed=1; /* not allowed because.... A HACK!!! 0 means to have no bonus levels to save a parameter */ if ( client_game_init_local( levelset_names_local[config.levelset_id_local] ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_EDIT: /* new set? */ if ( strequal( NEW_SET, edit_set ) ) { editor_file = calloc( 16, sizeof( char ) ); snprintf( path, sizeof(path)-1, "%s/%s/lbreakout2-levels", getenv( "HOME" )? getenv("HOME"):".", CONFIG_DIR_NAME ); if ( !enter_string( font, _("Set Name:"), editor_file, 12 ) || !file_check( path, editor_file, "w" ) ) { free( editor_file ); break; } else manager_update_set_list(); } else editor_file = strdup( edit_set ); if ( editor_init( editor_file ) ) { manager_fade( STK_FADE_OUT ); editor_run(); editor_clear(); manager_fade( STK_FADE_IN ); } free( editor_file ); editor_file = 0; break; case ACTION_QUICK_HELP: help_run(); break; case ACTION_CLIENT: manager_fade( STK_FADE_OUT ); client_run(); manager_fade( STK_FADE_IN ); break; default: break; } } manager_fade( STK_FADE_OUT ); /* delete stuff */ help_delete(); manager_delete(); chart_save(); chart_delete(); editor_delete(); exp_delete(); client_game_delete(); hint_delete_res(); theme_delete(); theme_delete_list(); stk_surface_free( &loading ); config_save(); if (hi_dir_chart_file) fclose(hi_dir_chart_file); return EXIT_SUCCESS; }
//------- Begin of function Misc::randomize --------// // void Misc::randomize() { set_random_seed(time(NULL)); }
int main(int argc, char *argv[]) { int i, c, rc; char buffer[1000]; struct mtwist_state *mt; enum planet_type pt; int count = 1; int npc_mode = 0; int planet_mode = 0; int robot_mode = 0; int ship_mode = 0; int taunt_mode = 0; int warning_mode = 0; set_random_seed(&mt); while (1) { int option_index; c = getopt_long(argc, argv, "c:nprstw", long_options, &option_index); if (c < 0) { break; } switch (c) { case 'c': rc = sscanf(optarg, "%d", &count); if (rc != 1) count = 0; break; case 'n': npc_mode = 1; break; case 'p': planet_mode = 1; break; case 'r': robot_mode = 1; break; case 's': ship_mode = 1; break; case 't': taunt_mode = 1; break; case 'w': warning_mode = 1; break; default: fprintf(stderr, "%s: Unknown option.\n", argv[0]); usage(argv[0]); } } if (taunt_mode + planet_mode + warning_mode + npc_mode + robot_mode + ship_mode == 0) usage(argv[0]); for (i = 0; i < count; i++) { if (taunt_mode) { infinite_taunt(mt, buffer, sizeof(buffer) - 1); printf("%s\n", buffer); } if (planet_mode) { pt = PlanetType(mt); planet_description(mt, buffer, sizeof(buffer) - 1, 60, pt); printf("%s\n", buffer); } if (warning_mode) { cop_attack_warning(mt, buffer, sizeof(buffer) - 1, 50); printf("%s\n", buffer); } if (npc_mode) { character_name(mt, buffer, sizeof(buffer) - 1); printf("%s\n", buffer); } if (robot_mode) { robot_name(mt, buffer, sizeof(buffer) - 1); printf("%s\n", buffer); } if (ship_mode) { ship_name(mt, buffer, sizeof(buffer) - 1); printf("%s\n", buffer); } } free(mt); return 0; }