Orthogonal variable spreading factor (OVSF) codes are widely used to provide variable data rates for supporting different bandwidth requirements in wideband code division multiple access (WCDMA) systems. Many works in the literature have intensively investigated to find an optimal dynamic code assignment scheme for OVSF codes. Unlike earlier studies, which assign OVSF codes using conventional (CCA) or dynamic (DCA) code allocation schemes, in this paper, stochastic optimization methods which are genetic algorithm (GA) and simulated annealing (SA) were applied which population is adaptively constructed according to existing traffic density in the OVSF code-tree. Also, the influences of the GA (selection, crossover and mutation techniques) and the SA (cooling schedules, number of inner loop) parameters were examined on the dynamic OVSF code allocation problem. Simulation results show that the GA and SA provide reduced code blocking probability and improved spectral efficiency when compared to the CCA and DCA schemes.