def _sample_weight(kappa, dim):
dim = dim - <NUM_LIT:1>  <EOL>b = dim / (np.sqrt(<NUM_LIT> * kappa ** <NUM_LIT:2> + dim ** <NUM_LIT:2>) + <NUM_LIT:2> * kappa)<EOL>x = (<NUM_LIT:1.> - b) / (<NUM_LIT:1.> + b)<EOL>c = kappa * x + dim * np.log(<NUM_LIT:1> - x ** <NUM_LIT:2>)<EOL>while True:<EOL><INDENT>z = np.random.beta(dim / <NUM_LIT>, dim / <NUM_LIT>)<EOL>w = (<NUM_LIT:1.> - (<NUM_LIT:1.> + b) * z) / (<NUM_LIT:1.> - (<NUM_LIT:1.> - b) * z)<EOL>u = np.random.uniform(low=<NUM_LIT:0>, high=<NUM_LIT:1>)<EOL>if kappa * w + dim * np.log(<NUM_LIT:1.> - x * w) - c >= np.log(u):<EOL><INDENT>return w<EOL><DEDENT><DEDENT>
Rejection sampling scheme for sampling distance from center on
    surface of the sphere.