Author |
Message |
bigshot3754 Guest
Offline
|
Posted: Wed Aug 18, 2004 2:57 pm Post subject: random setfreq rather than a static number |
 |
|
|
|
i'm editing the tv vex plugin, and it sets kicked people to freq 0 initially, i changed this to 85, but now i want this to be a random freq in 3-99 instead
sendPrivate(parse->item, "*setfreq 85");
thats what it is right now, i've read over the mervbot tutorial, with the section on random numbers and players, but it failed to work, and yes, i did include time.h
my guess is that my syntax was wrong or something, this is what i thought it should have been:
srand(time(NULL));
rand();
int tempkickofffreq = (int) (99 * ((float)rand()/RAND_MAX));
sendPrivate(parse->item, "You were kicked from the freq");
sendPrivate(parse->item, "*setfreq " + tempkickofffreq);
tho that would do 0-99 correct? (still didn't work btw)
i also tried putting the last tempkickofffreq as: int(tempkickofffreq)
and vegito suggested this to me:
srand(time(NULL));
int Random = rand()%51 + 1;
sendPrivate(parse->item, "You were kicked from the freq");
sendPrivate(parse->item, "*setfreq " + Random);
none have worth thus far, i'm hoping someone here will know what i'm talking about and can correct me
ty in advanced |
|
Back to top |
|
 |
Solo Ace Yeah, I'm in touch with reality...we correspond from time to time.

Age:37 Gender: Joined: Feb 06 2004 Posts: 2583 Location: The Netherlands Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Wed Aug 18, 2004 4:49 pm Post subject: |
 |
|
|
|
Should work:
_________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
 |
Underlord Novice
Gender: Joined: Feb 17 2004 Posts: 55 Offline
|
Posted: Wed Aug 18, 2004 5:33 pm Post subject: |
 |
|
|
|
sendPrivate(parse->item, "*setfreq " + tempkickofffreq);
should be:
sendPrivate(parse->item, "*setfreq " + (String) tempkickofffreq); |
|
Back to top |
|
 |
bigshot3754 Guest
Offline
|
Posted: Fri Aug 27, 2004 12:03 pm Post subject: |
 |
|
|
|
ty you three, i'll try yours first underlord |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Fri Aug 27, 2004 12:35 pm Post subject: |
 |
|
|
|
rand() % 97 + 3 will result in numbers from 3 to 99 _________________ 4,691 irradiated haggis! |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Fri Aug 27, 2004 2:32 pm Post subject: |
 |
|
|
|
rand % 97? you mean rand() * 97? _________________

Last edited by D1st0rt on Fri Aug 27, 2004 2:43 pm, edited 1 time in total |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Fri Aug 27, 2004 2:34 pm Post subject: |
 |
|
|
|
No, rand gives an int. The modulo operator (%) will take the remainder when devided by 97. Means you get a random number from 0 to 96.
+3 gives the proper offset. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Fri Aug 27, 2004 2:44 pm Post subject: |
 |
|
|
|
I thought rand gave a decimal between 0 and 1 |
|
Back to top |
|
 |
Deadly Seasoned Helper
Age:34 Gender: Joined: Oct 15 2003 Posts: 148 Location: Ontario Canada Offline
|
|
Back to top |
|
 |
Underlord Novice
Gender: Joined: Feb 17 2004 Posts: 55 Offline
|
Posted: Fri Aug 27, 2004 4:09 pm Post subject: |
 |
|
|
|
that code works fine deadly
rand() returns an int between 0 and RAND_MAX (32767)
never use something like 'rand() % 97'. The way the random number generator works, doing that will give 'less random' numbers, and often cycle between odd/even numbers. |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Fri Aug 27, 2004 6:12 pm Post subject: |
 |
|
|
|
Ooops. I got confused with BASIC for a sec there.
Underlord wrote: | never use something like 'rand() % 97'. The way the random number generator works, doing that will give 'less random' numbers, and often cycle between odd/even numbers. |
I've never noticed a problem doing it that way (which is always how I do it). |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Fri Aug 27, 2004 7:23 pm Post subject: |
 |
|
|
|
shows how much I know, in Java Math.random() returns a double between 0 and 1 |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Fri Aug 27, 2004 8:34 pm Post subject: |
 |
|
|
|
Underlord wrote: | that code works fine deadly
rand() returns an int between 0 and RAND_MAX (32767)
never use something like 'rand() % 97'. The way the random number generator works, doing that will give 'less random' numbers, and often cycle between odd/even numbers. |
That's retarded. If rand() is unreliable, then you should not use it at all. Going through a floating point conversion of it, makes it less efficient also, but doesn't make it any more random. If you don't like rand(), then download a better RNG, but always use the MOD operator.
Last edited by Mr Ekted on Fri Aug 27, 2004 11:44 pm, edited 1 time in total |
|
Back to top |
|
 |
Deadly Seasoned Helper
Age:34 Gender: Joined: Oct 15 2003 Posts: 148 Location: Ontario Canada Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Fri Aug 27, 2004 11:32 pm Post subject: |
 |
|
|
|
Can we see a little more of that code, please? |
|
Back to top |
|
 |
50% Packetloss Server Help Squatter

Age:40 Gender: Joined: Sep 09 2003 Posts: 561 Location: Santa Clarita, California Offline
|
Posted: Sat Aug 28, 2004 12:09 am Post subject: |
 |
|
|
|
Uint16 random_range(Uint16 lowest_number, Uint16 highest_number)
{
if(lowest_number > highest_number){
swap(lowest_number, highest_number);
}
Uint16 range = highest_number - lowest_number + 1;
return lowest_number + Uint16(range * rand()/(RAND_MAX + 1.0));
}
this is the function that i have used to do random ranges. I think i got it off a website. Its more efficient to just use the modulus operator. |
|
Back to top |
|
 |
_D1st0rt Guest
Offline
|
Posted: Sat Aug 28, 2004 12:34 am Post subject: |
 |
|
|
|
Merv comes with a prng |
|
Back to top |
|
 |
bigshot3754 Guest
Offline
|
Posted: Fri Sep 03, 2004 1:03 pm Post subject: |
 |
|
|
|
ok, this is still failing to work for me
Quote: |
if (name == parse->item->name)
{
if (parse->item->team != i)
{
sendPrivate(p, "The player is not on the freq");
return;
}
srand(time(NULL));
rand();
int tempkickofffreq = (int) (99 * ((float)rand()/RAND_MAX));
sendPrivate(parse->item, "You were kicked from the freq");
sendPrivate(parse->item, "*setfreq " + (String) tempkickofffreq);
return;
}
|
that what i have so far
Quote: |
command.cpp(556) : error C2664: 'void __thiscall botInfo::sendPrivate(struct Player *,char *)' : cannot convert parameter 2 from 'class String' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
|
if anyone could help me, it would be great, if u can't, i understand |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Fri Sep 03, 2004 2:16 pm Post subject: |
 |
|
|
|
Replace
sendPrivate(parse->item, "*setfreq " + (String) tempkickofffreq); |
with
sendPrivate(parse->item, String("*setfreq " + (String) tempkickofffreq)).msg; |
Should work.
Really it's better do do something like:
String message("*setfreq");
message += tempkickofffreq;
sendPrivate(parse->item, message.msg); |
More lines of C++, less lines of ASM (without optimization). |
|
Back to top |
|
 |
bigshot3754 Guest
Offline
|
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Thu Oct 21, 2004 5:48 pm Post subject: |
 |
|
|
|
Wow, you really didn't understand anything we told you?
First of all, rand() returns an int. Why are you float-ing it?
Second, learn what the % operator does and then modify the code yourself (to use it). |
|
Back to top |
|
 |
Underlord Novice
Gender: Joined: Feb 17 2004 Posts: 55 Offline
|
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
|
Back to top |
|
 |
bigshot3754 Guest
Offline
|
Posted: Thu Oct 21, 2004 10:51 pm Post subject: |
 |
|
|
|
Again, thank you for the resonses
@Cyan~Fire:
I'm very sorry I couldn't comprehend much from reading some lines of code involving the simplicities of random numbers. I'm always thankful for the help, but nothing provided to me so far has actually worked (what you gave me compiled fine but doesn't work when the command is sent :S) but I'm not complaining, I'm going to continue to use the items given here and hopefully get it working properly. |
|
Back to top |
|
 |
|