I sent an idea to the NBA about 6 years ago which would help avoid tanking. Instead of having the crap lottery where nobody sees the actual lottery until they put the teams in the envelopes, they could have a tournament to decide who gets the top pick. Every team who misses the playoffs is in the tournament. If you win, you get the first pick, come in second, you get the second pick, etc.....
This would force the teams who tank to have to play to get the first pick and give those teams fighting for a playoff spot the change for it as well. It would also give a few more games to those non-playoff teams and give their fans something to pull for even though their team can't win a title. It's not the perfect solution, but takes the opportunity for the NBA to just give the first pick to whoever they want to, which is probably what happens now.