4 Replies - 1716 Views - Last Post: 02 February 2012 - 06:28 PM

#1 mirz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-December 11

how to generate random score ranging from 75 to 100

Posted 01 February 2012 - 07:21 PM

hi!
i'm working on my project on flash 2008 i was wondering how would i generate score randomly from 75 to 100. it will be the scoring of my karaoke project...

score = Math.random();

createTextField("dynamic_txt", 1, 10, 10, 150, 30);
dynamic_txt.text = score;
dynamic_txt.textColor = 0xE3C13E
dynamic_txt.border = false;




those are my actionscript...i know there isn't much to my codes...

Is This A Good Question/Topic? 0
  • +

Replies To: how to generate random score ranging from 75 to 100

#2 meowbits  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 107
  • Joined: 31-January 12

Re: how to generate random score ranging from 75 to 100

Posted 01 February 2012 - 07:57 PM

/** 
* Generates a truly "random" number
* @return Random Number
*/ 
function randomNumber(low:Number, high:Number):Number
{
  return Math.floor(Math.random() * (1+high-low)) + low;
}


Taken off a different site and slightly modified.

You would use it like,

dynamic_txt.text=randomNumber(75,100);

And you just change the 75/100 to whatever you want for the low/high values.
Was This Post Helpful? 0
  • +
  • -

#3 mirz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-December 11

Re: how to generate random score ranging from 75 to 100

Posted 01 February 2012 - 08:14 PM

hi thanks for the reply...
um i think its working because its generating random numbers everytime i load the file...but the problem is its in decimal form... :helpsmilie:
like 0.643526231, etc..

help... :dontgetit:
Was This Post Helpful? 0
  • +
  • -

#4 meowbits  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 107
  • Joined: 31-January 12

Re: how to generate random score ranging from 75 to 100

Posted 01 February 2012 - 08:36 PM

/** 
* Generates a truly "random" number
* @return Random Number
*/ 
function randomNumber(low:Number, high:Number):Number
{
  return Math.floor(Math.random() * (1+high-low)) + low;
}

var score:int;
score = randomNumber(75,100);
trace(score);


Try throwing that someone in your code, it should print a number in your output while debugging.
I get whole numbers like you wanted.

Mod edit - Please :code:
Was This Post Helpful? 0
  • +
  • -

#5 mirz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 29-December 11

Re: how to generate random score ranging from 75 to 100

Posted 02 February 2012 - 06:28 PM

thanks for the help meowbuts..
its displaying whole numbers now... :bananaman:
but the thing is..its not displaying on my dynamic text on the screen thus it appears on the output panel...
how can i fix this?
var score;
function randomNumber(low:Number, high:Number):Number  
{  
	 return Math.floor(Math.random() * (1+high-low)) + low;  
}  

var score;  
score = randomNumber(75,100);  
score_txt.text = score;
score_txt.textColor = 0xE3C13E
score_txt.border = false;
score_txt.autoSize = true;
trace(score); 


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1