Author Topic: Random can't randomize Singles...  (Read 1114 times)

0 Members and 1 Guest are viewing this topic.

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Random can't randomize Singles...
« on: March 01, 2009, 05:23:58 am »
Random can't randomize Singles!
Is there a other Way?

Code: [Select]
  [*] Rand -> [Error] (4:47): Type mismatch

procedure Randomize(Number: Single);
begin
  WriteLn(FloatToStr(Random(-Number,Number)));
end;

procedure ActivateServer();
begin
  Randomize(3.14);
end;
« Last Edit: March 02, 2009, 07:56:19 am by y0uRd34th »

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Random can't randomize Singles...
« Reply #1 on: March 01, 2009, 05:42:47 am »
say you want a random number that is 0.0, 0.1, 0.2 ... 1.0. The best way that I can think of would be Random(0,10)/10
Basically just multiply what goes into random by a number and then divide it by that same number again.
I explained that badly but I think it's gettable.

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: Random can't randomize Singles...
« Reply #2 on: March 01, 2009, 06:32:57 am »
Yes good idea,Thanks!  ;)

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Random can't randomize Singles...
« Reply #3 on: March 01, 2009, 04:22:30 pm »
rather Random(0,11)/10 =P
Cause random never goes up to the high boundry, but one less

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: Random can't randomize Singles...
« Reply #4 on: March 02, 2009, 08:00:12 am »
Good to know^^

Next Question too Random:
How can i calculate the ammount of % which i have that it picks a selected Number?
1% = Random(0,100) Ok Easy
50% = Random(0,2)
Only decrease the 100 for every %? Not sure.

Hope you understand ;|
« Last Edit: March 02, 2009, 08:10:16 am by y0uRd34th »

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Random can't randomize Singles...
« Reply #5 on: March 02, 2009, 09:50:03 am »
Good to know^^

Next Question too Random:
How can i calculate the ammount of % which i have that it picks a selected Number?
1% = Random(0,100) Ok Easy
50% = Random(0,2)
Only decrease the 100 for every %? Not sure.

Hope you understand ;|
pretty much, or just use this pro function if you do something more complex: http://forums.soldat.pl/index.php?topic=32697.msg388941#msg388941

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: Random can't randomize Singles...
« Reply #6 on: March 02, 2009, 12:26:00 pm »
Ok, thanks,
but how works it?
I know i've to input [#,#,...,x]  but, how do i use it correctly?
Are the numbers in the Array the "%" ? Don't know what they bring :D

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Random can't randomize Singles...
« Reply #7 on: March 02, 2009, 02:35:47 pm »
you input the relative chances for your random. For example you want to get "1" in 20 cases out of 50, "2" in 10 cases out of 50 and "3" in 15 cases out of 50, your input should be [20,10,15,5] (you will get 4 in 5 cases out of 50).
Did that make any sense? :|

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Random can't randomize Singles...
« Reply #8 on: March 02, 2009, 04:59:04 pm »
:p

As for the formula:
where x is chance of hitting y, where y is the index number of the input array (liek: input[y]):

x = input[y]/(sum of all input)
 
some examples may help:

Code: [Select]
output := WRand([1,1]);
When inputing an array of 2 integers, output will be 0 or 1. The integers represent the chance of what the output will be. In this case the chance for 0 and 1 is equal, both 50% (formula: 1/(1+1) for both)

Code: [Select]
output := WRand([2,1]);
Again two integers, so output will be 0 or 1. Here the chance for 0 is twice as big as the chance for one. So 66% for 0 (2/(2+1)) and 33% chance for 1 (1/(2+1)).

Code: [Select]
output := WRand([2, 1, 1]);
Now three integers are inputed, so output can become 0 to 2. The chance for 0 is again twice as big as the chance for 1 and 2. 50% for 0 (2/(2+1+1)), 25% for both 1 and 2 (1/(2+1+1))

Code: [Select]
output := WRand([32, 18, 25, 25]);
If you really want to stick thinking in percentages, just make sure that the sum of all integers in the input array will be 100 (here 32+18+25+25). Then those integers will represent 100th parts, or percentages. Here there is 32% chance that output will be 0, 18% of 1 and 25% of both 2 and 3.
« Last Edit: March 02, 2009, 05:01:14 pm by JFK »
Come join: EliteCTF
Listen to: My Music

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: Random can't randomize Singles...
« Reply #9 on: March 03, 2009, 07:46:40 am »
Got it, i think, the Input only says the Chance of the Number, also [Chance for 0,Chance for 1,...]
right? Also when I do: [25,75] then has 0 the Chance of  25% and 1 75%?

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Random can't randomize Singles...
« Reply #10 on: March 03, 2009, 09:27:13 am »
That's correct. And to calculate the chance, you can use the formula.
Come join: EliteCTF
Listen to: My Music

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: Random can't randomize Singles...
« Reply #11 on: March 03, 2009, 10:30:05 am »
Good ;)

kthxbai