randintv.m

来自「ITU-T G.723.1 Speech Coder: Matlab imple」· M 代码 · 共 22 行

M
22
字号
function [iR, Seed] = RandIntV (Seed, N)% Generate a random integer in the interval [0, N-1].% The original C-code for random number generation was as follows:%   *p = (Word16)(((*p)*521L + 259) & 0x0000ffff)% This code uses integer arithmetic: The seed (Word16) is promoted% to long before being multiplied by 521. The result is masked to% 16 bits.%% Here we work with unsigned integer values (in Matlab doubles).   % $Id: RandIntV.m 1.5 2004/08/25 G.723.1-v2r1a $if (N == 1)  iR = 0;    % Don't invoke the random number generatorelse  Seed = mod (521 * Seed + 259, 65536);  iR = fix (mod (Seed, 32768) * N / 32768);endreturn

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?