Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 8th Apr 2010 17:28
Hi there, i was wondering if there was a way to random between a certain number? I know rnd() randoms from 1 to the specified number, how about if i wanted it to random from 200 to 300?
Silvester
20
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 8th Apr 2010 17:31 Edited at: 8th Apr 2010 17:32
I always work around that like this..



As far as I know there's no other way of doing this at this stage in time, besides perhaps a third party DLL I'm unfamiliar with.


EDP Map Editor[2D]
kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 8th Apr 2010 17:34
thank you for the very fast reply, and i didnt even think of that! Thanks =]
Silvester
20
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 8th Apr 2010 17:37
It's a silly solution really, do note that RND goes from 0 to the specified number, rather then 1.. So if you want to limit it to 1-50 you'd do something like..




EDP Map Editor[2D]
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Apr 2010 20:11
And if you'd like only the even or odd numbers from 200 to 300, you'd use something like:



TheComet

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 8th Apr 2010 20:14
Gets even more interesting when you want a random float between 200 and 300

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 8th Apr 2010 20:17 Edited at: 8th Apr 2010 23:55
( ( rnd( 1000.0 ) + 2000.0 ) / 10.0 )? :p

Rawwrr. Sig Fail.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Apr 2010 20:27


TheComet

Silvester
20
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 8th Apr 2010 21:10
Seems like it's Random RND day today?


EDP Map Editor[2D]
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 8th Apr 2010 23:03
Did you need to declare those globals?

Rawwrr. Sig Fail.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Apr 2010 23:51
Quote: "Gets even more interesting when you want a random float between 200 and 300"


Yes.

Quote: "(rnd(1000) + 2000) / 10 ?"


Oh dear.

Random certainly, but probably not what was wanted.

I'd use one of IanM's many PRNGs in his Matrix1 Utilites. No idea which one though.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 8th Apr 2010 23:56
Quote: "Oh dear.

Random certainly, but probably not what was wanted."


Fixed

Rawwrr. Sig Fail.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Apr 2010 00:24
Quote: "Did you need to declare those globals?"


If you don't, DBP declares them for you, but I don't trust that. Besides, it's professional to have every variable initialized at the top of your program. It's what you have to do in C++ or Java or any other of those many programming languages that aren't BASIC.

TheComet

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 9th Apr 2010 03:21
Quote: "If you don't, DBP declares them for you, but I don't trust that. Besides, it's professional to have every variable initialized at the top of your program. It's what you have to do in C++ or Java or any other of those many programming languages that aren't BASIC."


There's no reason to declare every variable like that global though... I mean, this:

function random_float(rnd_start,rnd_end,float_digits)
...
endfunction x#


isn't much different from this:

public float random_float(int rnd_start, int rnd_end, int float_digits)
{
...
}


Definitely not different enough (IMO) to really justify declaring everything global. I think declaring everything global is a good was to cause weird errors.


Anyways, @ kkun, it's a really good idea to keep in mind that 0<=rnd(x)<=x, so rnd(100) would return one of 101 possible results, while rnd(99) would return one of 100 possible results. It's not too tricky if you think it through, but I've had major pains because I've overlooked rnd statements


Login to post a reply

Server time is: 2026-07-26 15:31:34
Your offset time is: 2026-07-26 15:31:34