I am trying to program a game called Bubble Poke, and I have run into a small problem. The rand() function in toolchain is not random. It's the same every time. Every time I run the program, I get the same exact matrix values, even though I used rand() in a nested for loop. Is there a special command in toolchain that can assist me in making rand() actually random instead of predictable, or will I have to stick with a predictable matrix every time?
Here is the source code if you're interested:
Code:
Here is the source code if you're interested:
Code:
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <keypadc.h>
#include <graphx.h>
#include "gfx/logo_gfx.h"
void main(void){
int dots[10][10];
uint8_t i=1;
uint8_t j=1;
uint8_t color=1;
uint8_t randomNumber=1;
for(i=0;i<10;i++){
for(j=0;j<10;j++){
randomNumber = (rand()%2)+1;
if(randomNumber == 2) color++;
if(color == 7) color = 1;
if(color == 1) dots[i][j] = 224;
if(color == 2) dots[i][j] = 227;
if(color == 3) dots[i][j] = 231;
if(color == 4) dots[i][j] = 38;
if(color == 5) dots[i][j] = 24;
if(color == 6) dots[i][j] = 153;
}
}
gfx_Begin();
gfx_SetPalette(logo_gfx_pal, sizeof_logo_gfx_pal, 0);
gfx_FillScreen(1);
for(i=0;i<10;i++){
for(j=0;j<10;j++){
gfx_SetColor(dots[i][j]);
gfx_FillCircle_NoClip(20*i+20,20*j+20,9);
}
}
delay(5000);
gfx_End();
os_ClrHome();
}