[Bf-blender-cvs] [035d92dd1ac] functions: faster temporary random number function

Jacques Lucke noreply at git.blender.org
Fri Jun 28 16:04:30 CEST 2019


Commit: 035d92dd1ac6a2688078aaaea9d65f6e9d9fa9f7
Author: Jacques Lucke
Date:   Fri Jun 28 14:20:04 2019 +0200
Branches: functions
https://developer.blender.org/rB035d92dd1ac6a2688078aaaea9d65f6e9d9fa9f7

faster temporary random number function

===================================================================

M	source/blender/simulations/bparticles/actions.cpp

===================================================================

diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index c3dfa28acf6..8b051ae9076 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -1,5 +1,7 @@
 #include "actions.hpp"
 
+#include "BLI_hash.h"
+
 namespace BParticles {
 
 class KillAction : public Action {
@@ -53,10 +55,16 @@ class SpawnAction : public Action {
   }
 };
 
+static float random_number()
+{
+  static uint number = 0;
+  number++;
+  return BLI_hash_int_01(number) * 2.0f - 1.0f;
+}
+
 static float3 random_direction()
 {
-  return float3(
-      (rand() % 1000 - 500) / 500.f, (rand() % 1000 - 500) / 500.f, (rand() % 1000 - 500) / 500.f);
+  return float3(random_number(), random_number(), random_number());
 }
 
 class ExplodeAction : public Action {



More information about the Bf-blender-cvs mailing list