Random Nginx rewrites for AB testing

I would like to create an nginx rewrite from a location to multiple targets so i could do AB testing.

Something like:

rewrite ^/link/$ https://www.url1.com/ https://www.url2.com/ permanent;

When a visitor go to http://www.example.com/link/, it would send the same amount of visitors to url1.com and url2.com.

Thank you.