Hello, Random Float Numbers Problem!
How Can i make Random Numbers like this

0.2
23.5
13.3
0.3
18.2
so on!

i want this for my fishing system! for fish size's!
I'll hit you up with a link when I get home. Wait a bit.
Quote:
 Originally Posted by GeekSiMo
??
can't understand it can anyone define?
I suppose you could use something like this to generate normalized random floating point numbers (between 0 and 1):

pawn Код:
`stock Float:frandnorm(const RAND_MAX = 32767){    //Using C's RAND_MAX constant, make a random number up to RAND_MAX and    //divide it by RAND_MAX, normalizing it (higher RAND_MAX = higher precision)    return Float:random(RAND_MAX) / Float:RAND_MAX;}`
You could then multiply that normalized value by something to produce numbers specified by a maximum value (like random()):

pawn Код:
`stock Float:frand(const Float:max){    //Result will never exceed max, because we're multiplying a normalized (0 .. 1) value    //by the max (which will only ever give max or less)    return (frandnorm() * max);}`
Or even go as far to implement some form of range, like this:

pawn Код:
`stock Float:frandrange(const Float:min, const Float:max){    //Just offset range of random numbers by amount    return min + frand(max-min);}`
Take for example, if I wanted to generate random numbers between 0 and 20, I might use something like:

pawn Код:
`stock Float:frandnorm(const RAND_MAX = 32767){    return Float:random(RAND_MAX) / Float:RAND_MAX;}stock Float:frand(const Float:max){    return (frandnorm() * max);}main(){    //Print out header    printf("0 to 20:\r\n-----");    //Generate 5 random numbers between the interval 0 to 20, and print them out!    for(new i = 0; i < 5; i++)        printf("%f", frand(20));}`
Which gives me this output:

Код:
```0 to 20:
-----
18.555864
11.637317
6.126285
10.887173
1.890316```
pawn Код:
`new Float:MaxSize = 100.0; //This will be the largest size a fish can reach.    new Float:MinSize = 4.0; //This will be the smallest size a fish can reach.    new Float:RandSize = MinSize + float(random(floatround(MaxSize - MinSize) * 1000)) / 1000;    //Gives a random number between 4.0 (MinSize) and 100.0 (MaxSize). Results vary depending on the value of 'MaxSize' and 'MinSize'.`
nvm, already done with this! btw thank u all! for help!

Forum Jump: