random number generator

Non-platform specific questions.

random number generator

Postby Fojam » Sun Sep 18, 2011 2:18 am

how would i generate a random number between 1 and 500?

correct this if its wrong but is it this?
Code: Select all
Math.floor(Math.random()*500);
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: random number generator

Postby jimmynewguy » Sun Sep 18, 2011 2:58 am

Just use rand.
Code: Select all
int random = rand(499)+1;// gets a random number between 0 and maximum, that's why we have 499 and +1
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: random number generator

Postby Fojam » Sun Sep 18, 2011 2:46 pm

thanks that works. so the one in parenthesis is the maximum and the + number is the minimum?
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: random number generator

Postby savvy » Sun Sep 18, 2011 2:53 pm

you dont have to have a +, heres how it works
rand(500);
this would get a number ranging from 0 to 499 the +1 makes it range from 1 to 500.
you can use rand to get make any random thing, for example.. creating an actor in the view at a random point.

Code: Select all
x=view.x+rand(view.width);
y=view.y+rand(view.height);


:) savvy
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: random number generator

Postby Fojam » Sun Sep 18, 2011 3:08 pm

and is there a way to save the variable of a random number so it will load it when the application starts?
if i saved the random number in a variable named random, could i save that somewhere so that it would load it at runtime and display it in a text actor?
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: random number generator

Postby jimmynewguy » Sun Sep 18, 2011 3:12 pm

Fojam, Just use save/load vars
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: random number generator

Postby Fojam » Sun Sep 18, 2011 6:17 pm

sorry been a while since ive used GE. i took a break to learn actionscript so yeah.
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: random number generator

Postby savvy » Sun Sep 18, 2011 7:58 pm

yeah, make a variable called random..
random = rand(amount);
SaveVars("file","group");
(or whatever it is, i use my own save things)
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest