SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/03/2019, 12:19 AM   #1
qRazor
Big Clucker
 
Join Date: Jan 2016
Location: Oradea, Romania
Posts: 138
Reputation: 0
Default Random Float Number

Hi, how i can get a float number from random? Like random(1) to get 0.52.
qRazor is offline   Reply With Quote
Old 15/03/2019, 12:59 AM   #2
Romz
Banned
 
Join Date: Jun 2013
Location: Ukraine
Posts: 1,044
Reputation: 64
Default Re: Random Float Number

https://forum.sa-mp.com/showpost.php...52&postcount=3
Romz is offline   Reply With Quote
Old 15/03/2019, 12:59 AM   #3
d3Pedro
Huge Clucker
 
d3Pedro's Avatar
 
Join Date: Apr 2012
Location: darkness
Posts: 292
Reputation: 80
Default Re: Random Float Number

https://wiki.sa-mp.com/wiki/Floatround
__________________
d3Pedro is offline   Reply With Quote
Old 15/03/2019, 09:38 AM   #4
qRazor
Big Clucker
 
Join Date: Jan 2016
Location: Oradea, Romania
Posts: 138
Reputation: 0
Default Re: Random Float Number

Quote:
Originally Posted by ****** View Post
There's a much better version in y_utils. The one in that post takes `(max, min)` as parameters, which makes no sense. The one in y_utils either takes `(max)` or `(min, max)`:

https://github.com/pawn-lang/YSI-Inc....inc#L421-L454
Thank you!

EDIT: I need a little help again.. how i can extract an integer from float? Floatround over 0.50 rounded to a value of 1, it's possible to make if i have a value of 0.99, the integer number to be 0?

Last edited by qRazor; 15/03/2019 at 10:32 AM.
qRazor is offline   Reply With Quote
Old 15/03/2019, 10:27 AM   #5
Kaliber
High-roller
 
Kaliber's Avatar
 
Join Date: Jun 2012
Location: Localhost
Posts: 1,066
Reputation: 149
Default Re: Random Float Number

Just check the wiki: https://wiki.sa-mp.com/wiki/Floatround

There you see, that you have diffrent rounding Methods: https://wiki.sa-mp.com/wiki/Floatround_method

For example:

PHP Code:
floatround(0.99floatround_floor); //returns 0 
__________________
Kaliber is offline   Reply With Quote
Old 15/03/2019, 10:34 AM   #6
qRazor
Big Clucker
 
Join Date: Jan 2016
Location: Oradea, Romania
Posts: 138
Reputation: 0
Default Re: Random Float Number

Quote:
Originally Posted by Kaliber View Post
Just check the wiki: https://wiki.sa-mp.com/wiki/Floatround

There you see, that you have diffrent rounding Methods: https://wiki.sa-mp.com/wiki/Floatround_method

For example:

PHP Code:
floatround(0.99floatround_floor); //returns 0 
I want to return a value from a variable, for example x = 0.99, or x = 0.12, or x = 0.51, you understand now? And x in this case to be 0.
qRazor is offline   Reply With Quote
Old 15/03/2019, 10:58 AM   #7
Kaliber
High-roller
 
Kaliber's Avatar
 
Join Date: Jun 2012
Location: Localhost
Posts: 1,066
Reputation: 149
Default Re: Random Float Number

Yes dude, i understood that.

But it seems, you dont understand the use of a function, so read some basics: https://wiki.sa-mp.com/wiki/Scripting_Basics

You just have to write:

PHP Code:
floatround(xfloatround_floor); 
__________________
Kaliber is offline   Reply With Quote
Old 15/03/2019, 02:27 PM   #8
qRazor
Big Clucker
 
Join Date: Jan 2016
Location: Oradea, Romania
Posts: 138
Reputation: 0
Default Re: Random Float Number

Quote:
Originally Posted by Kaliber View Post
Yes dude, i understood that.

But it seems, you dont understand the use of a function, so read some basics: https://wiki.sa-mp.com/wiki/Scripting_Basics

You just have to write:

PHP Code:
floatround(xfloatround_floor); 
Yeah it was my bad and thank you! I apologize again man.
qRazor is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How get float number Banditukas Scripting Help 1 30/03/2015 01:54 PM
Whats the easy way to get (Float:minx, Float:miny, Float:maxx, Float:maxy) for GangZoneCreate Issam Scripting Help 7 18/09/2011 07:16 PM
doing random number with number range defined henry jiggy Help Archive 3 10/08/2011 11:59 PM
Random number, then pick string out of an array depending on number? Robbin237 Help Archive 2 26/02/2009 07:26 PM


All times are GMT. The time now is 03:44 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.