コード例 #1
0
/**
 Send random order (buy/sell) to the market server
 **/
void sendRandomBuyAndSellOrder () {
    int isBuy = getRandomValue(0, 2);
    int quantity = getRandomValue(1, 5);
    int maxPrice = getRandomValue(1, DEFAULT_ACTION_PRICE+50);
    
    sendTransactionOrder(pipe_marketOrder, pipe_serverResponse, quantity, maxPrice, isBuy);
}
コード例 #2
0
ファイル: SyntheticInput.cpp プロジェクト: notedit/licode
void SyntheticInput::tick() {
  // This method will be called periodically to send audio/video frames
  time_point now = clock_->now();
  if (now >= next_audio_frame_time_) {
    sendAudioFrame(audio_frame_size_);
    next_audio_frame_time_ += audio_period_;
  }
  if (now >= next_video_frame_time_) {
    bool is_keyframe = false;
    size_t frame_size = getRandomValue(video_avg_frame_size_, video_dev_frame_size_);
    if (now - last_video_keyframe_time_ > kDefaultVideoKeyframePeriod || keyframe_requested_) {
      is_keyframe = true;
      frame_size = getRandomValue(video_avg_keyframe_size_, video_dev_keyframe_size_);
    }
    while (frame_size > kMaxPacketSize) {
      sendVideoframe(is_keyframe, false, kMaxPacketSize);
      is_keyframe = false;
      frame_size = frame_size - kMaxPacketSize;
    }
    sendVideoframe(is_keyframe, true, frame_size);

    next_video_frame_time_ += video_period_;
  }
  now = clock_->now();
  if ((next_video_frame_time_ <= now || next_audio_frame_time_ <= now) && consecutive_ticks_ < kMaxConsecutiveTicks) {
    consecutive_ticks_++;
    tick();
  } else {
    consecutive_ticks_ = 0;
  }
}
void RandomValueBlock::eachFrame(double timeSinceLastFrame) {
    // advance position value:
    double stepTime = m_currentStepTime;
    if (m_inputNode->isConnected() && !m_inputNode->constData().absoluteMaximumIsProvided()) {
        // there is a non-absolute Block connected:
        stepTime *= m_inputNode->getValue();
    }
    if (stepTime == 0) return;
    double progress = timeSinceLastFrame / stepTime;
	if ((m_pos + progress) > 1) {
		// get new values:
        m_oldValues = m_newValues;
        fillRandom(m_newValues);
        m_currentStepTime = m_stepTime + m_stepTime * m_timeVaration * (getRandomValue() * 2 - 1);
        if (m_currentStepTime <= 0) {
            m_currentStepTime = 0.1;
        }
	}
	m_pos = fmod(m_pos + progress, 1.0);

	// calculate current value:
    double fadePos = m_pos / m_fadeRatio;
    HsvDataModifier out(m_outputNode);
	if (fadePos < 1) {
        for (int x=0; x < out.width; ++x) {
            for (int y=0; y < out.height; ++y) {
                double newValue = m_oldValues.at(x, y).v * (1 - fadePos) + m_newValues.at(x, y).v * fadePos;
                out.set(x, y, 0, 0, newValue);
            }
        }
	} else {
        out.setFrom(m_newValues);
    }
}
コード例 #4
0
ファイル: RRGenerationHandler.cpp プロジェクト: ytjjyy/licode
void RRGenerationHandler::sendRR(std::shared_ptr<RRPackets> selected_packet_info) {
  if (selected_packet_info->ssrc != 0) {
    uint64_t now = ClockUtils::timePointToMs(clock::now());
    uint64_t delay_since_last_sr = selected_packet_info->last_sr_ts == 0 ?
      0 : (now - selected_packet_info->last_sr_ts) * 65536 / 1000;
    RtcpHeader rtcp_head;
    rtcp_head.setPacketType(RTCP_Receiver_PT);
    rtcp_head.setSSRC(selected_packet_info->ssrc);
    rtcp_head.setSourceSSRC(selected_packet_info->ssrc);
    rtcp_head.setHighestSeqnum(selected_packet_info->extended_seq);
    rtcp_head.setSeqnumCycles(selected_packet_info->cycle);
    rtcp_head.setLostPackets(selected_packet_info->lost);
    rtcp_head.setFractionLost(selected_packet_info->frac_lost);
    rtcp_head.setJitter(static_cast<uint32_t>(selected_packet_info->jitter.jitter));
    rtcp_head.setDelaySinceLastSr(static_cast<uint32_t>(delay_since_last_sr));
    rtcp_head.setLastSr(selected_packet_info->last_sr_mid_ntp);
    rtcp_head.setLength(7);
    rtcp_head.setBlockCount(1);
    int length = (rtcp_head.getLength() + 1) * 4;

    memcpy(packet_, reinterpret_cast<uint8_t*>(&rtcp_head), length);
    getContext()->fireWrite(std::make_shared<dataPacket>(0, reinterpret_cast<char*>(&packet_), length, OTHER_PACKET));
    selected_packet_info->last_rr_ts = now;

    ELOG_DEBUG("%s, message: Sending RR, ssrc: %u, type: %u lost: %u, frac: %u, cycle: %u, highseq: %u, jitter: %u, "
        "dlsr: %u, lsr: %u", connection_->toLog(), selected_packet_info->ssrc, selected_packet_info->type,
        rtcp_head.getLostPackets(), rtcp_head.getFractionLost(), rtcp_head.getSeqnumCycles(),
        rtcp_head.getHighestSeqnum(), rtcp_head.getJitter(), rtcp_head.getDelaySinceLastSr(),
        rtcp_head.getLastSr());

    uint16_t selected_interval = selectInterval(selected_packet_info);
    selected_packet_info->next_packet_ms = now + getRandomValue(0.5 * selected_interval, 1.5 * selected_interval);
  }
}
void RandomValueBlock::fillRandom(HsvMatrix& matrix) const {
    for (int x=0; x < matrix.width(); ++x) {
        for (int y=0; y < matrix.height(); ++y) {
            matrix.at(x, y).v = getRandomValue();
        }
    }
}
コード例 #6
0
ファイル: RtcpRrGenerator.cpp プロジェクト: notedit/licode
std::shared_ptr<DataPacket> RtcpRrGenerator::generateReceiverReport() {
  uint64_t now = ClockUtils::timePointToMs(clock_->now());
  uint64_t delay_since_last_sr = rr_info_.last_sr_ts == 0 ?
    0 : (now - rr_info_.last_sr_ts) * 65536 / 1000;
  uint32_t expected = rr_info_.extended_seq - rr_info_.base_seq + 1;
  if (expected < rr_info_.packets_received) {
    rr_info_.lost = 0;
  } else {
    rr_info_.lost = expected - rr_info_.packets_received;
  }


  uint8_t fraction = 0;
  uint32_t expected_interval = expected - rr_info_.expected_prior;
  rr_info_.expected_prior = expected;
  uint32_t received_interval = rr_info_.packets_received - rr_info_.received_prior;

  rr_info_.received_prior = rr_info_.packets_received;
  int64_t lost_interval = static_cast<int64_t>(expected_interval) - received_interval;
  if (expected_interval != 0 && lost_interval > 0) {
    fraction = (static_cast<uint32_t>(lost_interval) << 8) / expected_interval;
  }

  rr_info_.frac_lost = fraction;
  RtcpHeader rtcp_head;
  rtcp_head.setPacketType(RTCP_Receiver_PT);
  rtcp_head.setSSRC(ssrc_);
  rtcp_head.setSourceSSRC(ssrc_);
  rtcp_head.setHighestSeqnum(rr_info_.extended_seq);
  rtcp_head.setSeqnumCycles(rr_info_.cycle);
  rtcp_head.setLostPackets(rr_info_.lost);
  rtcp_head.setFractionLost(rr_info_.frac_lost);
  rtcp_head.setJitter(static_cast<uint32_t>(rr_info_.jitter.jitter));
  rtcp_head.setDelaySinceLastSr(static_cast<uint32_t>(delay_since_last_sr));
  rtcp_head.setLastSr(rr_info_.last_sr_mid_ntp);
  rtcp_head.setLength(7);
  rtcp_head.setBlockCount(1);
  int length = (rtcp_head.getLength() + 1) * 4;

  memcpy(packet_, reinterpret_cast<uint8_t*>(&rtcp_head), length);
  rr_info_.last_rr_ts = now;

  ELOG_DEBUG("message: Sending RR, ssrc: %u, type: %u lost: %u, frac: %u, cycle: %u, highseq: %u, jitter: %u, "
      "dlsr: %u, lsr: %u", ssrc_, type_,
      rtcp_head.getLostPackets(), rtcp_head.getFractionLost(), rtcp_head.getSeqnumCycles(),
      rtcp_head.getHighestSeqnum(), rtcp_head.getJitter(), rtcp_head.getDelaySinceLastSr(),
      rtcp_head.getLastSr());

  uint16_t selected_interval = selectInterval();
  rr_info_.next_packet_ms = now + getRandomValue(0.5 * selected_interval, 1.5 * selected_interval);
  rr_info_.last_packet_ms = now;
  return (std::make_shared<DataPacket>(0, reinterpret_cast<char*>(&packet_), length, type_));
}
コード例 #7
0
ファイル: auth.c プロジェクト: andreiw/polaris
/*
 * Function: createSessionKey
 *
 * Arguments:	key - Pointer to session key buffer
 *		keyLen - Pointer to Length of session key
 *		spi - Pointer to SPI
 *
 * Description: This function is used to create pseudo-random
 *		session keys, and SPI values. Note that the
 *		keys created here are by no means random, and
 *		this function is only used for testing purposes.
 *
 * Returns:	none
 */
static void
createSessionKey(uint8_t *key, uint32_t *keyLen, uint32_t *spi)
{
	int i;

	/*
	 * First we create the SPI value.
	 */
	*spi = htonl(getRandomValue());

	/*
	 * Now we create the session key
	 */
	for (i = 0; i < MAX_SESSION_KEY_LEN; i++) {
		key[i] = getRandomValue();
	}

	/*
	 * Set the length
	 */
	*keyLen = MAX_SESSION_KEY_LEN;

}
コード例 #8
0
int generateColValues(const std::vector<struc_tabColumn>& _vecAllColsInfo, std::map<int,std::vector<std::string> >& mapColValues)
{
  size_t pos_type = std::string::npos;
  std::vector<struc_tabColumn>::const_iterator itr = _vecAllColsInfo.begin();

  for(int col_index=1;itr != _vecAllColsInfo.end();itr++,col_index++)
  {
    struc_tabColumn _cols = (*itr);
    std::cout<<"name="<<_cols.sName<<",type="<<_cols.sType<<",format="<<_cols.sFormat<<std::endl; 

    
    pos_type = _cols.sFormat.find(std::string("incremental"));
    if(pos_type != std::string::npos)
    {
      size_t next_pos_1 = _cols.sFormat.find("(",pos_type);
      size_t next_pos_2 = _cols.sFormat.find(")",next_pos_1);
      int inc_val = atoi(_cols.sFormat.substr(next_pos_1+1,next_pos_2 - next_pos_1-1).c_str());

      std::cout<<"incremental found="<<inc_val<<std::endl;
      mapColValues.insert(make_pair(col_index,getIncrementalValue(0,inc_val)));

    }
    else if(std::string::npos != (pos_type = _cols.sFormat.find(std::string("randomstring"))))
    {
      size_t next_pos_1 = _cols.sFormat.find("(",pos_type);
      size_t next_pos_2 = _cols.sFormat.find(",",next_pos_1);
      int inc_val1 = atoi(_cols.sFormat.substr(next_pos_1+1,next_pos_2 - next_pos_1-1).c_str());

      next_pos_1 = _cols.sFormat.find(")",next_pos_2);
      int inc_val2 = atoi(_cols.sFormat.substr(next_pos_2+1,next_pos_1 - next_pos_2-1).c_str());

      std::cout<<"randomstring found val1="<<inc_val1<<",val2="<<inc_val2<<std::endl;
      mapColValues.insert(make_pair(col_index,getRandomValue(inc_val1,inc_val2)));

    }
    else
    {
     //no matches found
      std::cout<<"format error \n";

     return ERR_FORMAT_ERROR;

    }

   
  }
 return SUCCESS;
}
コード例 #9
0
void ParticleSystem::spawnParticle()
{
	Particle particle;

	particle.age = 0;
	particle.color = color[0];
	particle.grow = getRandomValue(grow, growVariance);
	particle.duration = getRandomValue(particleDuration, particleDurationVariance);
	particle.speed = getRandomDirection(direction, directionVariance) * getRandomValue(speed, speedVariance);
	particle.shrink = getRandomValue(shrink, shrinkVariance);
	particle.size = getRandomValue(size[0], sizeVariance[0]);
	particle.templateSize[0] = particle.size;
	particle.templateSize[1] = getRandomValue(size[1], sizeVariance[1]);
	particle.templateSize[2] = getRandomValue(size[2], sizeVariance[2]);

	// Shape
	particle.position = position;
	particle.vertexOffset = vertexSource->add();

	particles.push_back(particle);
}
コード例 #10
0
int main()
{
   Shape* shapeArray[20] = {0};
   Shape* resultArray[20] = {0};
   int i = 0;

   std::cout << "Create rectange:\n";
   for ( ; i < 10; i++ )
   {
      shapeArray[i] = new Rectangle( i, 
                                     getRandomValue(), 
                                     getRandomValue(), 
                                     getRandomValue(),
                                     getRandomValue() );
      std::cout << shapeArray[i]->getNo() << ':' << shapeArray[i]->getArea() << '\n';
   }

   std::cout << "Create circle:\n";

   for ( ; i < 20; i++ )
   {
      shapeArray[i] = new Circle( i, 
                                     getRandomValue(), 
                                     getRandomValue(),
                                     getRandomValue() );
      std::cout << shapeArray[i]->getNo() << ':' << shapeArray[i]->getArea() << '\n';
   }

   int k = 0;
   for ( int j = 0; j < 20; j++ )
   {
      if ( NULL != shapeArray[j] )
      {
         if ( shapeArray[j]->getArea() >= 50 )
         {
            resultArray[k] = shapeArray[j];
            k++;
         }
      }
   }

   std::cout << "Large than 50 items:\n";
   while( k > 0 )
   {
      k--;
      std::cout << resultArray[k]->getNo() << ':' << resultArray[k]->getArea() << '\n';
      std::cout.flush();
   }
   

   for ( int i = 0; i < 20; i++ )
   {
      //release objects on HEAP
      delete shapeArray[i];
      //Here, do we need to delete resultArray[i] or can we?
      /*
      shapeArray[i] = NULL;
      if ( NULL != resultArray[i] )
      {
         std::cout << i << "is not empty";
         delete resultArray[i];
      }
      */
   }
   return 0;
}
コード例 #11
0
ファイル: bankers.c プロジェクト: 0x4849/cmput379
void runProcesses(int *allocationArray, int *workArray, int *maxArray, int *requestedResources, int *needArray, int *waitingQueue, int *maxAvailableResources, int *releaseResources,  int numProc, int numRes)
{

  int isAllZero;
  int offSet;
  int i, j, k, isSafeToAllocateRes;
  int requestedRandomAction;
  int requestRandomRes;
  int *tempWork;

  char reqGranted[100], reqNotGranted[100], curRequest[100];


  offSet = 0;
  checkIfDeadLock(waitingQueue, numProc);
  for (i=0; i < numProc; i++)
  {
    /* Let 0 = Do Nothing, 1 = Request Resources, 2 = Release Resources */
    /* Return random value [0,3) */
    
    if (waitingQueue[i] == 1)
    {
      /* If the process is currently in the waiting queue, then skip execution */
      continue;
    }

    requestedRandomAction = getRandomValue(0, 3);
    /* If we want to just continue execution, then go ahead and do so */
    if (requestedRandomAction == 0)
    {
      continue;
    }

    /* This will correspond to a resource release request */
    else if (requestedRandomAction == 2)
    {
      /* If all of our allocated resources are currently zero, and the
         process still wanted to release some resources, then we simply
         continue execution, and we skip this part.

         It is not really necessary -- because we could simply
         release 0 resources each time and then try to satisfy remaining
         requests on the waiting queue.

         So this here is open for interpretation. Would a process
         with zero resources allocated ever tell the operating system
         that it wishes to resource its resources? In my opinion, no,
         so that it is why I have chosen to skip execution here. */
        
      if (allResourcesAreZero(numRes, i * numRes, allocationArray))
      {
        continue;
      }
      else
      {
        offSet = i * numRes;
        j = 0;
        isAllZero = 1;
          
        while (j < numRes)
        {
          requestRandomRes = getRandomValue(0, allocationArray[offSet]+1);
          if (requestRandomRes)
          {
            isAllZero = 0;
          }
          releaseResources[j] = requestRandomRes;
          offSet++;
          j++;
        }
        /* Another situation completely open for interpretation.
           Here we are releasing 0 resources of each resource type.
           The professor told me that it is not valid to request 0
           resources of each type, so in my opinion, it is not valid to
           release all 0 resources of each type, so if the request involves
           all zero resources, then simply skip execution. */
        if (isAllZero)
        {
          continue;
        }

        printf("P%d has released ", i+1);
        printReleaseResources(releaseResources, numRes);
        releaseTheResources(releaseResources, allocationArray, workArray, i*numRes, numRes);

        /* After resources have been released, it is necessary to update
           the allocation, work, need arrays */
        makeInitialChangesToWorkAndNeed(numRes, i*numRes, allocationArray, requestedResources, maxArray, needArray, workArray);

        /* Try to satisfy all requests on the waiting queue since we have released
           resources */
        tryToSatisfyAllRequests(numRes, numProc, waitingQueue, requestedResources, allocationArray, workArray, needArray, maxArray, maxAvailableResources); 
      }

    }

    /* The requested action was to request resources, so this will start a chain of
       events that includes using the Banker's algorithm if needed to see if the
       system can remain in a safe state or not */
    else if (requestedRandomAction == 1)
    {

      offSet = i * numRes;
      j = 0;
      while (j < numRes)
      {
        requestRandomRes = getRandomValue(0, needArray[offSet]+1);
        requestedResources[offSet] = requestRandomRes;
        offSet++;
        j++;
      }


      /* All of the resources requested of each instance was 0.
         The professor told me that this request is not valid, so I am
         skippping execution here */
      
      if (allResourcesAreZero(numRes, i*numRes, requestedResources))
      {
        continue;
      }

      /* Print a snapshot of the system after the request has been made */
      printCurrentSnapshot(allocationArray, requestedResources, workArray, maxArray, needArray,waitingQueue, maxAvailableResources, numProc, numRes);

      sprintf(curRequest, "came from P%d", i+1);
      printRequest(numRes, requestedResources, i*numRes, curRequest); 
      printf("\n");
      offSet = i * numRes;
      
      /* Check to see if the system is in a safe state for giving the request or not */
      isSafeToAllocateRes = checkSafeState(workArray, needArray, maxArray, allocationArray, requestedResources, waitingQueue, numProc, numRes, offSet);

      if (isSafeToAllocateRes)
      {
        /* if it's safe to allocate the resource, then print snapshot and make the
           changes necessary to the given arrays */
        sprintf(reqGranted, "from P%d has been granted", i+1);
        printRequest(numRes, requestedResources, offSet, reqGranted); 
        makeInitialChangesToWorkAndNeed(numRes, offSet, allocationArray, requestedResources, maxArray, needArray, workArray);
        /* Remember to clear out requestedResources since request has been granted. */
        removeRequestedResources(numRes,requestedResources, offSet);

        /* print snapshot after request was OK'd */
        printCurrentSnapshot(allocationArray, requestedResources, workArray, maxArray, needArray,waitingQueue, maxAvailableResources, numProc, numRes);
          
      }
      else
      {
        /* Request not satisfied -- add the process to the waiting queue */
        sprintf(reqNotGranted, "from P%d cannot be satisfied, P%d is in waiting state", i+1, i+1);
        printRequest(numRes, requestedResources, offSet, reqNotGranted);
        waitingQueue[i] = 1;          
      }
       

    }

     
        
  }
}
コード例 #12
0
ファイル: mmo_math.c プロジェクト: RexFuzzle/qss-solver
unsigned long mmo_getRandomValue(int n)
{
	return getRandomValue(n);
}
コード例 #13
0
Vector2f ParticleSystem::getRandomDirection(float base, float variance)
{
	float angle = getRandomValue(base, variance);

	return Vector2f(cosf(angle), sinf(angle));
}