seed

What is random seed about?

匆匆过客 提交于 2019-12-05 02:36:53
问题 For example the code below. It has a random class. However it always produce the same output everywhere . In this case which item is the seed? source: link import java.util.Random; public class RandomTest { public static void main(String[] s) { Random rnd1 = new Random(42); Random rnd2 = new Random(42); System.out.println(rnd1.nextInt(100)+" - "+rnd2.nextInt(100)); System.out.println(rnd1.nextInt()+" - "+rnd2.nextInt()); System.out.println(rnd1.nextDouble()+" - "+rnd2.nextDouble()); System

Seed images in heroku with paperclip

荒凉一梦 提交于 2019-12-05 01:14:31
问题 When I run heroku run rake db:seed I get Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/image20130219-2-1gk1yip.png[0]' Command :: composite -gravity Center /app/public/media/watermark.png "/tmp/image20130219-2-1gk1yip.png[0]" -resize "1x1<" "/tmp/image20130219-2-1gk1yip.png20130219-2-1ng5f6c[0]" Command :: file -b --mime '/tmp/image20130219-2-1gk1yip.png20130219-2-1ng5f6c' Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/image20130219-2-1gk1yip20130219-2-t3caqg

Rails 3: Multiple has_one associations & seeding

蹲街弑〆低调 提交于 2019-12-04 13:45:53
问题 I'm working with a data concept that Rails doesn't seem to do great with - a Route has two (and only two) Airports. I finally figured out how to hard-code my foreign keys so that they would be sensible. My models/route.rb is pretty simple: class Route < ActiveRecord::Base has_one :airport, :foreign_key => 'from_airport_id', :class_name => 'Airport' has_one :airport, :foreign_key => 'to_airport_id', :class_name => 'Airport' end This all seems to be working fine but I can't seem to get it to

How to set up a Rake task for seeding

徘徊边缘 提交于 2019-12-04 10:11:54
(This is really a newbie question about Rake & Rails & dependencies in general. Trying to wrap my head around how all this fits together) Basically, I want a Rake task that acts like seed.rb but is called separately. It adds test data for the development environment, while my seed.rb provides basic data for all environments. The script, family_seed.rb, uses FactoryGirl to generate some records. It looks like this: require File.expand_path('../../config/environment', __FILE__) require './spec/factories' Family.delete_all Member.delete_all zinsser = Factory.create(:family, :last_name=>'Zinsser',

random number generation of doubles between two intervals [a,b]

回眸只為那壹抹淺笑 提交于 2019-12-04 09:49:46
I need to generate X random double numbers uniformly distributed between two intervals [a,b], where a and b are also double numbers. Those X numbers need to be generated inside of a class function, say myclass::doSomething(a,b) . The thing is that the intervals [a,b] passed to the doSomething(a,b) function change each time the doSomething(a,b) function is called by another class function, say doThat() . I would like a solution that allows me to: 1. Have an engine with a higher scope, ideally, it should be seeded only once per application run. 2. The X random double numbers generated inside of

Seed multiple rows at once laravel 5

大城市里の小女人 提交于 2019-12-04 08:16:39
问题 I'm currently trying to seed my users table. If I try it like this with 2 rows, it fails. It works fine if I just use a single array instead of the 2 arrays inside the $users array to create some fake data. What am I doing wrong, what is the proper way to do this? class UserTableSeeder extends Seeder { public function run() { DB::table('users')->delete(); $users = [ ['id' => 1, 'name' => 'Stephan de Vries', 'username' => 'stephan', 'email' => 'stephan-v@gmail.com', 'password' => bcrypt(

Entity Framework Code First: How to seed a database for unit testing

天涯浪子 提交于 2019-12-04 08:04:55
My question and code is based on the Code First Entity Framework Unit Test Examples blog post. I am using SQL Compact 4.0 and as such my unit tests are running against the actual database using real data similar to what is being described in the blog post. I want to seed my production database with default values in some of the tables but when running my unit tests I want to add additional data and update some of the default values. I have created a custom Initializer class that seeds the database with the default values. For my unit tests I have created another custom Initializer that

How to seed the production database using the Capistrano gem?

社会主义新天地 提交于 2019-12-04 07:30:37
问题 I am using Ruby on Rails 3.0.9 and I would like to seed the production database in order to add some record without re-building all the database (that is, without delete all existing records but just adding some of those not existing yet). I would like to do that because the new data is needed to make the application to work. So, since I am using the Capistrano gem, I run the cap -T command in the console in order to list all available commands and to know how I can accomplish what I aim: $

Setting seed boost::random

*爱你&永不变心* 提交于 2019-12-04 02:56:54
I would like to reset random sequences by using different seed numbers. When running this test code: boost::mt19937 gener(1); boost::normal_distribution<> normal(0,1); boost::variate_generator<boost::mt19937&,boost::normal_distribution<> > rng(gener, normal); cout << rng() << endl; cout << rng() << endl; cout << rng() << endl; gener.seed(2); cout << rng() << endl; cout << rng() << endl; gener.seed(1); cout << rng() << endl; gener.seed(2); cout << rng() << endl; gener.seed(3); cout << rng() << endl; I get the following output: # seed(1) via constructor -2.971829031 1.706951063 -0.430498971 #

PHP中的服务容器与依赖注入的思想

寵の児 提交于 2019-12-03 21:07:53
依赖注入 当A类需要依赖于B类,也就是说需要在A类中实例化B类的对象来使用时候,如果B类中的功能发生改变,也会导致A类中使用B类的地方也要跟着修改,导致A类与B类高耦合。这个时候解决方式是,A类应该去依赖B类的接口,把具体的类的实例化交给外部。 就拿我们业务中常用的通知模块来说。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <?php /** * 定义了一个消息类 * Class Message */ class Message{ public function seed() { return 'seed email' ; } } /* * 订单产生的时候 需要发送消息 */ class Order{ protected $messager = '' ; function __construct() { $this ->messager = new Message(); } public function seed_msg() { return $this ->messager->seed(); } } $Order = new Order(); $Order ->seed_msg(); 上面的代码是我们传统的写法。首先由个消息发送的类。然后在我们需要发送消息的地方