Write a small C program that simulates 6 dice. Use your own random number generator
- User
Write a small C program that simulates 6 dice. Use your own random number generator
Assistant
Here is a C program that simulates rolling 6 dice:
#include <stdio.h> #include <stdlib.h> #include <time.h> int rollDice() { return rand() % 6 + 1; // Returns a random int between 1 and 6 } int main() { srand(time(NULL)); // Seed the random number generator int dice1 = rollDice(); int dice2 = rollDice(); int dice3 = rollDice(); int dice4 = rollDice(); int dice5 = rollDice(); int dice6 = rollDice(); printf("Dice 1: %d\n", dice1); printf("Dice 2: %d\n", dice2); printf("Dice 3: %d\n", dice3); printf("Dice 4: %d\n", dice4); printf("Dice 5: %d\n", dice5); printf("Dice 6: %d\n", dice6); }This program:
- Seeds the random number generator using the current time
- Defines a rollDice() function to generate a random number between 1 and 6
- Calls rollDice() 6 times to simulate rolling 6 dice
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.