CMD:randword(playerid, arg[])
{
RandomizeWord(arg);
SendClientMessage(playerid, 0xFFFF0000, arg);
return 1;
}
stock RandomizeWord(word[])
{
new tmp;
new r;
for(new i = strlen(word) - 1; i >= 0; i--)
{
r=random(strlen(word));
tmp = word[i];
word[i] = word[r];
word[r] = tmp;
}
}
|
Well since strings are just arrays you can randomize your array pretty easy...
Код:
CMD:randword(playerid, arg[])
{
RandomizeWord(arg);
SendClientMessage(playerid, 0xFFFF0000, arg);
return 1;
}
stock RandomizeWord(word[])
{
new tmp;
new r;
for(new i = strlen(word) - 1; i >= 0; i--)
{
r=random(strlen(word));
tmp = word[i];
word[i] = word[r];
word[r] = tmp;
}
}
|
|
Well since strings are just arrays you can randomize your array pretty easy...
Код:
CMD:randword(playerid, arg[])
{
RandomizeWord(arg);
SendClientMessage(playerid, 0xFFFF0000, arg);
return 1;
}
stock RandomizeWord(word[])
{
new tmp;
new r;
for(new i = strlen(word) - 1; i >= 0; i--)
{
r=random(strlen(word));
tmp = word[i];
word[i] = word[r];
word[r] = tmp;
}
}
|
stock Scramble(string[], size=sizeof(string))
{
new rand, tmp;
for(new i=0; i < size; ++i) if(string[i] == ' ' || string[i] == '\0') size=i-1;
for(new i=0; i < size; ++i)
{
rand=random(size);
tmp=string[i];
string[i]=string[rand];
string[rand]=tmp;
}
return 1;
}
|
The only problem with that code is that if I randomized a word, say "computer", it could get scrambled as "mputccoo", as it has the possibility of re-using letters
|