Randoming negative float between 2 floats
#1

I used ******' frandom function which lets you randomize float.

And now i have 2 negative floats (Y plane coordinates) which i want to randomize to get another float but when i use this code

pawn Код:
Float:frandom(Float:max, Float:min = 0.0, dp = 4) // Credit to ******
{
    new
        Float:mul = floatpower(10.0, dp),
        imin = floatround(min * mul),
        imax = floatround(max * mul);
    return float(random(imax - imin) + imin) / mul;
}

CreateObject(3571, frandom(1789.6992188,1771.8000488), frandom(-1938.5000000,-1924.5999756), frandom(12.500000000, 712.50000000), 0, 0, 0);
It always give me

Код:
print:
[20:18:00] 1781.285644 ,199397.187500 ,184316.359375
[20:18:00] 1783.055175 ,110607.679687 ,191494.968750
[20:18:00] 1789.378540 ,182083.125000 ,1943.275634
[20:18:00] 1785.997192 ,46609.656250 ,155602.921875
[20:18:00] 1785.291259 ,178319.640625 ,190371.953125
[20:18:00] 1781.454223 ,201125.640625 ,133184.828125
[20:18:00] 1788.326660 ,168695.765625 ,57329.253906
[20:18:00] 1784.657958 ,205569.734375 ,53580.062500
[20:18:00] 1787.192382 ,148641.234375 ,107991.781250
[20:18:00] 1787.833984 ,47619.042968 ,24258.021484
[20:18:00] 1779.168823 ,5412.126464 ,2613.375244
[20:18:00] 1774.139648 ,89909.921875 ,128043.367187
[20:18:00] 1777.411254 ,163303.187500 ,34511.160156
[20:18:00] 1786.023193 ,15723.910156 ,20348.349609
[20:18:00] 1779.414550 ,201686.031250 ,130236.210937
[20:18:00] 1780.560546 ,144122.593750 ,51953.535156
[20:18:00] 1774.301025 ,138575.859375 ,65237.082031
[20:18:00] 1785.686035 ,127782.000000 ,74931.578125
[20:18:00] 1788.721557 ,201427.984375 ,25928.902343
[20:18:00] 1772.198608 ,45012.789062 ,175937.953125
[20:18:00] 1775.039550 ,207914.109375 ,123303.695312
[20:18:00] 1777.855224 ,191452.218750 ,148601.093750
[20:18:00] 1783.049438 ,20134.806640 ,91818.828125
[20:18:00] 1781.497558 ,90582.179687 ,55012.882812
[20:18:00] 1778.527221 ,78556.054687 ,26738.197265
[20:18:00] 1771.874023 ,194681.265625 ,208673.812500
[20:18:00] 1772.985961 ,213241.234375 ,147563.125000
[20:18:00] 1778.544799 ,182825.750000 ,209100.625000
[20:18:00] 1786.234619 ,134188.828125 ,84510.062500
[20:18:00] 1776.358032 ,130512.257812 ,165684.625000
[20:18:00] 1788.316406 ,119798.039062 ,50065.925781
[20:18:00] 1772.557250 ,5414.750488 ,162221.984375
[20:18:00] 1786.712768 ,176186.250000 ,18184.085937
[20:18:00] 1777.860839 ,123019.507812 ,196051.078125
[20:18:00] 1777.303955 ,117639.171875 ,93633.359375
[20:18:00] 1781.574584 ,175370.296875 ,61808.664062
[20:18:00] 1786.145629 ,187705.109375 ,178948.578125
[20:18:00] 1779.260375 ,203976.859375 ,156271.281250
[20:18:00] 1779.377441 ,172735.390625 ,47290.414062
[20:18:00] 1787.458740 ,135803.500000 ,149463.437500
[20:18:00] 1785.260375 ,3714.529541 ,210125.203125
[20:18:00] 1784.722045 ,204523.312500 ,180242.734375
[20:18:00] 1772.035400 ,86209.828125 ,57976.320312
[20:18:00] 1774.223999 ,7994.285644 ,56817.261718
[20:18:00] 1782.004760 ,103976.343750 ,171397.281250
[20:18:00] 1776.425048 ,100660.125000 ,83832.054687
[20:18:00] 1779.436401 ,53715.847656 ,163625.812500
[20:18:00] 1779.225952 ,161469.031250 ,19415.189453
[20:18:00] 1785.130004 ,133916.421875 ,58175.941406
[20:18:00] 1779.409057 ,175825.062500 ,202080.968750
[20:18:00] 1788.756958 ,158024.359375 ,175037.531250
[20:18:00] 1774.881347 ,67357.648437 ,17730.798828
[20:18:00] 1778.530029 ,51685.316406 ,22439.933593
[20:18:00] 1784.719970 ,72016.664062 ,174669.781250
[20:18:00] 1777.206054 ,28758.646484 ,142621.171875
[20:18:00] 1785.753051 ,106881.835937 ,39258.757812
[20:18:00] 1784.808837 ,146385.437500 ,145626.968750
[20:18:00] 1782.576049 ,165442.250000 ,154587.171875
[20:18:00] 1778.686767 ,12319.159179 ,62294.437500
[20:18:00] 1778.163940 ,169314.437500 ,152066.468750
[20:18:00] 1783.764404 ,142213.218750 ,193072.765625
[20:18:00] 1789.450805 ,29557.378906 ,96633.953125
[20:18:00] 1782.615966 ,195128.546875 ,104215.734375
[20:18:00] 1782.550048 ,179732.796875 ,99375.421875
[20:18:00] 1771.929443 ,69797.187500 ,153095.984375
[20:18:00] 1774.881835 ,19579.537109 ,-214086.687500
[20:18:00] 1773.017578 ,29668.394531 ,212243.171875
[20:18:00] 1787.831542 ,76395.359375 ,208840.187500
[20:18:00] 1773.723144 ,153917.046875 ,113385.867187
[20:18:00] 1774.591552 ,172779.687500 ,167380.359375
[20:18:00] 1784.776000 ,205613.234375 ,170333.890625
[20:18:00] 1789.213378 ,214673.843750 ,132146.296875
[20:18:00] 1782.863159 ,23015.142578 ,35766.160156
[20:18:00] 1789.446411 ,82764.453125 ,60307.125000
[20:18:00] 1777.477539 ,122500.953125 ,45221.121093
[20:18:00] 1776.900024 ,195271.671875 ,63710.085937
[20:18:00] 1776.432373 ,45866.621093 ,17684.615234
[20:18:00] 1782.462036 ,38178.363281 ,89951.203125
[20:18:00] 1782.790039 ,114947.273437 ,55713.183593
[20:18:00] 1788.680541 ,121266.804687 ,31721.888671
[20:18:00] 1783.633422 ,167754.296875 ,43710.808593
[20:18:00] 1782.859252 ,128919.695312 ,71404.656250
[20:18:00] 1782.449584 ,138389.828125 ,98344.156250
[20:18:00] 1788.685546 ,209907.359375 ,68242.835937
[20:18:00] 1782.484375 ,146385.593750 ,57416.078125
[20:18:00] 1776.656860 ,55702.996093 ,43096.171875
[20:18:00] 1785.308593 ,104089.593750 ,44032.292968
[20:18:00] 1777.285644 ,89907.695312 ,121227.046875
[20:18:00] 1783.934814 ,51766.734375 ,132739.968750
[20:18:00] 1778.207153 ,141998.781250 ,86415.523437
[20:18:00] 1777.428833 ,75869.007812 ,175139.046875
[20:18:00] 1777.442382 ,208519.890625 ,180223.531250
[20:18:00] 1788.218750 ,163550.000000 ,93107.390625
[20:18:00] 1787.388793 ,147143.250000 ,61097.566406
[20:18:00] 1774.834594 ,134967.046875 ,87199.445312
[20:18:00] 1781.287231 ,62843.519531 ,116727.320312
[20:18:00] 1783.514770 ,37467.781250 ,199473.484375
[20:18:00] 1787.846191 ,119689.843750 ,212169.156250
[20:18:00] 1773.641235 ,106631.085937 ,128051.929687
[20:18:00] 1773.590942 ,44149.136718 ,98173.554687
Positive values! which causing the objects were placed far away than what i expected to be.
Reply
#2

pawn Код:
CreateObject(3571, frandom(1789.6992188,1771.8000488), -frandom(-1938.5000000,-1924.5999756), frandom(12.500000000, 712.50000000), 0, 0, 0);
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
In what world is -1938.5 larger than -1924.6? Look at the parameter order:

pawn Код:
(Float:max, Float:min)
Silly me, thanks
Reply
#4

Another problem, objects won't appear, even tho i fixed the mistakes.
Reply
#5

pawn Код:
for(new i=0; i<100; i++)
    {
        CreateObject(972,1771.8000488,-1924.5999756,12.5+(7*i),0.0000000,0.0000000,0.0000000);
        CreateObject(972,1796.5996094,-1924.6992188,12.5+(7*i),0.0000000,0.0000000,0.0000000);
        CreateObject(972,1785.5996094,-1906.8994141,12.5+(7*i),0.0000000,0.0000000,270.0000000);
        CreateObject(972,1789.6992188,-1938.5000000,12.5+(7*i),0.0000000,0.0000000,90.0000000);
        CreateObject(3370, frandom(1789,1771), frandom(-1924,-1938), frandom(712, 12), 0, 0, 0);
    }
Shouldn't be more than 500, right?

And for streamer, i'm making this for FS so would be easier if not using any plugin. But if there is no other way i think i'll use it.
Reply
#6

The limit is 1000 objects
https://sampwiki.blast.hk/wiki/Limits
Reply
#7

That is just a absolute limit Dark_Rain in actuality your likely to start crashing before hitting 1000 objects.
Reply
#8

Quote:
Originally Posted by DaRk_RaiN
Посмотреть сообщение
The limit is 1000 objects
https://sampwiki.blast.hk/wiki/Limits
I know that -_- but I believe that loop creates 500 objects.
Reply
#9

Bump, anyone?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)