Lua implementation of systematic resampling.