小编mis*_*yde的帖子

在C中生成随机字母

这是我的代码.我正在尝试生成随机字母,但我看到相同的字母.例如:(Y HTGDHFBSHXCHF Y FUXZWDYKLXI)我该如何解决?只是我需要混合字母而不是相同的字母.非常感谢.

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void random_string(char * string, unsigned length)
{
    /* Seed number for rand() */
    srand((unsigned int) time(0));


    int i;
    for (i = 0; i < length; ++i)
    {
        string[i] = rand() % 26 + 'A';
    }

    string[i] = '\0';
}

int main(void)
{
    char s[26];
    random_string(s, 26);
    printf("%s\n", s);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c random encryption

2
推荐指数
1
解决办法
1457
查看次数

标签 统计

c ×1

encryption ×1

random ×1