How to invert randomly a string?
#4

Quote:
Originally Posted by Pottus
View Post
This would actually be quite similar to a card shuffle algorithm actually why not look a few up and see if you can get it to work.
Why didn't you just link him your RandomizeWord function?

Here it is, it does exactly what you want:

pawn Code:
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;
    }
}
Example code:

pawn Code:
#include <a_samp>

public OnFilterScriptInit()
{
    new word[9];
   
    word = "Computer";
    RandomizeWord(word);

    printf("%s", word);

    return true;
}

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;
    }
}
Output:

Code:
[16:11:41]   Loading filterscript 'comp.amx'...
[16:11:41] Cpumeotr
Sauce: http://forum.sa-mp.com/showpost.php?...68&postcount=3
Reply


Messages In This Thread
How to invert randomly a string? - by Hantex. - 02.09.2014, 13:35
Re: How to invert randomly a string? - by Pottus - 02.09.2014, 13:45
AW: Re: How to invert randomly a string? - by Hantex. - 02.09.2014, 13:56
Re: How to invert randomly a string? - by Dignity - 02.09.2014, 14:11
AW: How to invert randomly a string? - by Hantex. - 02.09.2014, 14:28

Forum Jump:


Users browsing this thread: 1 Guest(s)