Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from datetime import datetime
- from scipy.stats import levy
- random.seed(datetime.now())
- def direction():
- """pick an initial random direction with uniform distribution"""
- direction_xy = polarToCartesian(random.randint(0, 7))
- # custom parameters
- stride_normal = 1
- stride_long = 30
- loc = 0
- scale = 1
- threshold = 25
- """stride length using a random pick from levy distribution"""
- r = levy.rvs(loc, scale)
- # use < to enable stride on tail
- # use > to enable stride on head
- stride = stride_normal if r < threshold else stride_long
- #print([direction_xy, stride])
- return([direction_xy, stride])
- def polarToCartesian(direction):
- # 0 1 2
- # 7 b 3
- # 6 5 4
- return {
- 0: [-1, -1],
- 1: [-1, 0],
- 2: [-1, +1],
- 3: [ 0, +1],
- 4: [+1, +1],
- 5: [+1, 0],
- 6: [+1, -1],
- 7: [ 0, -1]
- } [direction]
- ### TEST
- for t in range(10):
- print(direction())
- ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement