Deficits in executive function, visuospatial abilities, and cognitive embodiment may impair gait performance. This study aimed to investigate the effect of age on random number generation (RNG) performance during forward and backward locomotion to assess cognitive flexibility and cognitive embodiment during walking. Another aim was to examine the effect of age on the associations of RNG performance during walking with stride time variability (STV), the percentage of double support (DS%), and visuospatial abilities as measured by a spatial orientation test (SOT). Twenty old (age 68.8 ± 5.3, 65% female) and 20 young (age 25.2 ± 2.2, 45% female) adults generated random numbers during backward walking (BW) and forward walking (FW) over-ground and over a treadmill with an internal focus of attention and visual-attentive distraction; six walking conditions in total. To assess cognitive flexibility, sample entropy was calculated for each RNG sequence. The average of the first 5 numbers in each RNG task was calculated to assess the relationship between small/large numbers and movement direction. STV and DS% were recorded using inertial measurement units, and spatial orientation was measured using a computerized test. The older subjects had less flexibility in generating random numbers in three of the six walking conditions. A negative correlation between RNG flexibility and STV was found in older adults during treadmill BW with visual-attentive distraction and forward over-ground walking, whereas no correlations were demonstrated in the young group. The spatial orientation score (a higher value means a worse outcome) correlated positively with RNG flexibility in the older group under all walking conditions, suggesting that older adults with better visuospatial orientation have lower cognitive flexibility, and vice versa. There was no correlation between small/large numbers and direction of motion in either group. The correlation between RNG flexibility and STV may indicate similar executive control of verbal and gait rhythmicity in old adults. Conversely, our results suggest that cognitive flexibility and visuospatial ability may decline differently.