I need to random a new specific position for the player each N cycles of game loop. So my idea was use a ROM array (data) and a rand function using (&) operator for fast processing following the random terrain documentation : https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#rand
However it doesn't work. It is like the response is the same array position always and it returns strange positions randomly haha.. It is more random than I want lol.
I'm using Standard Kernel, with these options below and basic logic for this example :
  ;***************************************************************
  ;
  ;  Initializes the batari Basic compiler directives.
  set kernel_options pfcolors player1colors no_blank_lines
  set tv ntsc
  set romsize 32k
  set optimization speed
  set smartbranching on
  set optimization noinlinedata
  set optimization inlinerand
  ;***************************************************************
  ;
  ;  Debug. The rem below is removed when I want to check to see
  ;  if I'm going over cycle count during tests.
  ;
  ; set debug
  ;*************************************************************** 
  ;
  ;  Variable aliases go here (DIMs).
  ;```````````````````````````````````````````````````````````````
  ;  _Animation_Frame.
  ;
  dim _Player_Animation_Frame = a
  dim _PlayerPosition = b
   
  dim p1posx=player0x.d
  dim p1posy=player0y.e
__GameStart
  COLUPF = $0E
  _Player_Animation_Frame = 0
  drawscreen
  ;***************************************************************
  ;
  ;  Road Section Positions X for Spawn Enemies
  ;
   data _Road_Pos
   49,77,105
end
__MAIN_LOOP_STAGE1
  COLUPF = $0E
  
  ; Change position each 15 cycles 
  if _Player_Animation_Frame = 0 then temp1 = (rand&3) 
  if _Player_Animation_Frame = 15 then temp1 = (rand&3)
  if _Player_Animation_Frame = 30 then temp1 = (rand&3)
  ; GETTING RANDOM ARRAY POSITION
  if _Player_Animation_Frame < 10 then gosub __Player_Sprite : COLUP0 = $84 : p1posx = _Road_Pos[temp1] : p1posy = 50
  if _Player_Animation_Frame > 9  && _Player_Animation_Frame < 20 then gosub __Player_Sprite : COLUP0 = $34 : p1posx = _Road_Pos[temp1] : p1posy = 50
  if _Player_Animation_Frame > 19 then gosub __Player_Sprite : COLUP0 = $0E : p1posx = _Road_Pos[temp1] : p1posy = 50
  _Player_Animation_Frame = _Player_Animation_Frame + 1
  if _Player_Animation_Frame = 30 then _Player_Animation_Frame = 0 
  drawscreen
  goto __MAIN_LOOP_STAGE1
__Player_Sprite
 player0:
 %01111110
 %01111110
 %11111111
 %11111111
 %11111111
 %01111110
 %01111110
end
 return thisbank
 
                        
It seems happen because i use the optimization kernel option
set optimization noinlinedata
I'm no sure, but i solve the issue using the following strategy, creating a subroutine for random position and put the value of array position in a variable, so after that i set the player position using the variable instead get array position inline.
The following code works fine :)