fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main() {
  6.  
  7. int hold_power_3_persen1 = 1;
  8. int hold_power_3_persen2 = 10;
  9. int hold_power_3_persen3 = 30;
  10. int hold_power_3_persen4 = 59;
  11.  
  12. int values[] = {hold_power_3_persen1, hold_power_3_persen2, hold_power_3_persen3, hold_power_3_persen4};
  13.  
  14. srand(time(NULL));
  15.  
  16. // สุ่ม index ของอาเรย์
  17. int randomIndex = rand() % (sizeof(values) / sizeof(values[0]));
  18.  
  19. // แสดงค่าที่สุ่มได้
  20. printf("Random Value: %d\n", values[randomIndex]);
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Random Value: 59