Raised This Month: $ Target: $400
 0% 

How to make random Numbers with Random function?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ScHrAnZ DiNgEnS
Senior Member
Join Date: Sep 2007
Old 01-03-2010 , 02:11   How to make random Numbers with Random function?
Reply With Quote #1

Can someone tell me how to make real random Numbers ?
The random function is only a algorithm, so the results are always the same.

Example:

make a random from 0 to 2 and u get results like this:

Quote:
2
0
1
0
2
0
1
0
2
0
1
0
2
.....
In c++ its possible to initialize the randomfunction with a number Example like time class

PHP Code:
#include <time.h>

srand( (unsigned)timeNULL ) );
int i rand()%3
now we have different results and not always the same.

[QESTION] Is it possible to make something like this with pawn for amxx?
__________________

Last edited by ScHrAnZ DiNgEnS; 01-03-2010 at 06:26.
ScHrAnZ DiNgEnS is offline
Send a message via ICQ to ScHrAnZ DiNgEnS Send a message via AIM to ScHrAnZ DiNgEnS
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-03-2010 , 05:03   Re: How to make random Numbers with Random function?
Reply With Quote #2

You get the same result with random() and random_num() ?
__________________
Arkshine is offline
MouseSplash!
Veteran Member
Join Date: Dec 2009
Location: En Tu Mente!
Old 01-03-2010 , 05:48   Re: How to make random Numbers with Random function?
Reply With Quote #3

this???

PHP Code:
switch (random_num(13))
{
        case 
1:       2
        
case 2:       1
        
case 3:       0

MouseSplash! is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 01-03-2010 , 06:08   Re: How to make random Numbers with Random function?
Reply With Quote #4

new i = random( 3 ) % 2; ? o_O
__________________
xPaw is offline
ScHrAnZ DiNgEnS
Senior Member
Join Date: Sep 2007
Old 01-03-2010 , 06:27   Re: How to make random Numbers with Random function?
Reply With Quote #5

sorry, it must be "int i = rand()%3" to get numbers from 0 to 2.

I test random_num() to time....
__________________
ScHrAnZ DiNgEnS is offline
Send a message via ICQ to ScHrAnZ DiNgEnS Send a message via AIM to ScHrAnZ DiNgEnS
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 01-03-2010 , 06:34   Re: How to make random Numbers with Random function?
Reply With Quote #6

So you wanted to get random number from 0 to 3 ?
just do random_num( 0, 3 );
__________________
xPaw is offline
ScHrAnZ DiNgEnS
Senior Member
Join Date: Sep 2007
Old 01-03-2010 , 06:44   Re: How to make random Numbers with Random function?
Reply With Quote #7

no, u did not understand me correct.

func random is not random at all, and after a few results u get exact the same results.

random_num seems to be working, 1020 results without the exact same results. i try it out now for random, maybe i test it to short...
__________________
ScHrAnZ DiNgEnS is offline
Send a message via ICQ to ScHrAnZ DiNgEnS Send a message via AIM to ScHrAnZ DiNgEnS
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-03-2010 , 06:50   Re: How to make random Numbers with Random function?
Reply With Quote #8

The higher is the number the better result you will get. random_num() is an engine call so I don't know what method it uses, random() is more the method you can see in xs_irand().
__________________
Arkshine is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 01-03-2010 , 07:06   Re: How to make random Numbers with Random function?
Reply With Quote #9

new i = random( 1024 ) % 3; lol
__________________
xPaw is offline
ScHrAnZ DiNgEnS
Senior Member
Join Date: Sep 2007
Old 01-03-2010 , 07:12   Re: How to make random Numbers with Random function?
Reply With Quote #10

Quote:
Originally Posted by xPaw View Post
new i = random( 1024 ) % 3; lol
what are u trying to do or maybe what are u try to tell me?
__________________
ScHrAnZ DiNgEnS is offline
Send a message via ICQ to ScHrAnZ DiNgEnS Send a message via AIM to ScHrAnZ DiNgEnS
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode