Untitled

 avatar
unknown
plain_text
5 months ago
835 B
3
Indexable
#include <stdio.h>

int generate_random_number(int x0, int a, int m) {
    return (a * x0) % m;
}

int main() {
    int x0, a, c, m;
    int random_number;

    printf("Enter the initial seed value (x0): ");
    scanf("%d", &x0);

    printf("Enter the multiplier (a): ");
    scanf("%d", &a);

    printf("Enter the increment (c, typically 0 for multiplicative): ");
    scanf("%d", &c);

    printf("Enter the modulus (m): ");
    scanf("%d", &m);

    if (c != 0) {
        printf("Warning: For multiplicative congruential method, c should be 0.\n");
    }

    printf("\nGenerated random numbers (four digits):\n");
    for (int i = 0; i < 10; i++) {
        x0 = generate_random_number(x0, a, m);
        random_number = x0 % 10000;
        printf("%d\n", random_number);
    }

    return 0;
}
Editor is loading...
Leave a Comment