Total Complexity | 5 |
Total Lines | 31 |
Duplicated Lines | 41.94 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | # Author: Simon Blanke |
||
2 | # Email: [email protected] |
||
3 | # License: MIT License |
||
4 | |||
5 | import random |
||
6 | import numpy as np |
||
7 | |||
8 | |||
9 | View Code Duplication | def set_random_seed(nth_process, random_state): |
|
|
|||
10 | """ |
||
11 | Sets the random seed separately for each thread |
||
12 | (to avoid getting the same results in each thread) |
||
13 | """ |
||
14 | if nth_process is None: |
||
15 | nth_process = 0 |
||
16 | |||
17 | if random_state is None: |
||
18 | random_state = np.random.randint(0, high=2 ** 31 - 2, dtype=np.int64) |
||
19 | |||
20 | random.seed(random_state + nth_process) |
||
21 | np.random.seed(random_state + nth_process) |
||
22 | |||
23 | |||
24 | def move_random(ss_positions): |
||
25 | position = [] |
||
26 | for search_space_pos in ss_positions: |
||
27 | pos_ = random.choice(search_space_pos) |
||
28 | position.append(pos_) |
||
29 | |||
30 | return np.array(position) |
||
31 |