由 is used to emphasize the people who should be responsible for something and purposiveness is very strong.
被 is used to emphasize to what results some actions done by somebody lead and purposiveness is not strong.
a. 水果由我来买。
b. 由我来买水果。
c. 杯子被他打碎了。
d. 自行车被人偷走了。
Sentence a&b mainly indicate it’s “ 我” that is responsible for buying the fruits instead any other people. The person who should do this job is arranged on purpose so the purposiveness is very strong.
Sentence c mainly tells the glasses was broken and sentence d tells the bicycle was stolen. The result is broken and stolen. As for who broke the glasses and who stole the bicycle is not important.