Browse Source

generate a different random number (#5882)

jcheron 5 years ago
parent
commit
799af7def2
1 changed files with 5 additions and 2 deletions
  1. 5 2
      frameworks/Ruby/rails/app/controllers/hello_world_controller.rb

+ 5 - 2
frameworks/Ruby/rails/app/controllers/hello_world_controller.rb

@@ -37,12 +37,15 @@ class HelloWorldController < ApplicationController
     queries = 1 if queries < 1
     queries = 1 if queries < 1
     queries = 500 if queries > 500
     queries = 500 if queries > 500
 
 
-    numbers = (1..10000).to_a.sample(queries)
+    numbers = (1..10000).to_a.sample(queries).sort
     worlds = numbers.map do |id|
     worlds = numbers.map do |id|
       # get a random row from the database, which we know has 10000
       # get a random row from the database, which we know has 10000
       # rows with ids 1 - 10000
       # rows with ids 1 - 10000
       world = World.select(:id, :randomNumber).find(id)
       world = World.select(:id, :randomNumber).find(id)
-      world.update_attribute(:randomNumber, Random.rand(1..10000))
+      begin
+        rn = Random.rand(1..10000)
+      end while rn == world.randomNumber
+      world.update_attribute(:randomNumber, rn)
       world
       world
     end
     end