ID:265823
Mar 25 2008, 9:11 pm
|
|
What I want to know is what's the difference between the two when you could have them used in exactly the same operations?
|
Mar 25 2008, 9:23 pm
|
|
They're nothing alike. prob(x) is true x% of the time, and false the rest. random() doesn't exist. rand(min,max) generates a random integer between min and max. rand() generates a random fraction between 0 and 1.
|
In response to Garthor
|
|
What I meant is that they are used in similar ways.
ie mob And I made an error in the title. And yes, I know I made a bunch of errors, but you get the idea. Right? |
In response to Demon_F0rce
|
|
Not quite, they're both quite different. rand() generates a random number between two numbers provided as arguments, prob() will return true if a probability chance determined by the argument hits successfully.
var/rand_num = rand(1,1000) // Can be anything between 1 and 1,000 |
In response to Nadrew
|
|
I realise this, but what I'm saying is that, in the end, they both basically work out the same things. Even though they end up with different results. Which is what explained before. You randomise one and two, and then it tells you what it is. And with probability, you either get one or two. I can take it beyond that, too, and make it so ten things could happen, and they both could be used in the process.
|
In response to Demon_F0rce
|
|
Except they don't work out the same thing at all, one generates a wide array of numbers of a random nature, the other just does a probability roll and returns true or false. They both have widely different applications that the other can't do easily or efficiently. I'm willing to bet prob() is less CPU intensive as well since it has to process far less information and do less work to return a result. While your example shows a method of making them function the same, it's not the ideal application of the rand() function since you don't need to generate more than a simple 50/50 chance there. rand() also isn't going to make it as easy on you if you want, say a 31% chance of a single value being hit and no other values.
|
In response to Nadrew
|
|
All I'm saying is that they can be used to work out the same functions. It would be easier with prob() in your examples, yet at the same time it can be done with rand(). (Jeez, this could end up ugly =/)
|
In response to Demon_F0rce
|
|
All I'm saying is that they can be used to work out the same functions. It would be easier with prob() in your examples, yet at the same time it can be done with rand(). (Jeez, this could end up ugly =/) Yeah prob() is performing a function which can be emulated with rand. if(rand()*100 < 90) will have nearly identical results as if(prob(90)) However for percentiles prob is obviously cleaner in code. But prob can't generate a range of random numbers which is important for stuff like coming up with something like random damage. Addition and multiplication can also be used to come to the same solution var/n = 4*4 var/n2 = 0 for(var/i = 0; i < 4; i++) n2 += 4 var/n3 = 4<<2 n, n2, and n3 will all end up with the same results. However all the operators have all their own uses and just because certain uses can all come up with the same results doesn't mean they aren't all individually important. But I think the original question as to how the two functions differ has already been answered :P. |
Generally, whenever there are 2 ways to get the same solution, I choose the one that is easier to understand and maintain. However, if the piece of code is inside a loop or causing network traffic, I might choose a harder to understand/maintain solution if it is the most efficient.
|
In response to Theodis
|
|
Theodis wrote:
But prob can't generate a range of random numbers which is important for stuff like coming up with something like random damage. Sure it can! proc/reallygoddamndumb(var/min, var/max) The key of this conversation is the distinction between "can" and "should." |
In response to Garthor
|
|
Since you actually brought this up, I might as well reply.
Garthor wrote: Sure it can! Of course it can't. Your custom proc could, obviously, but not prob(), which just can't, and only returns 1 or 0, unlike rand(). The key of this conversation is the distinction between "can" and "should." No. I suppose it'd be the distinction between just a proc, and between a different, new, custom, unrelated (:P) proc that uses another proc. |
In response to Kaioken
|
|
Why not bitch at Theodis? He did the same thing, only it was inline.
|