Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

how to get random numbers?

4 posters

Go down  Message [Page 1 of 1]

1how to get random numbers? Empty how to get random numbers? Sun May 14, 2023 7:46 pm

KarstenLehmann



Hello,
when I use the following lines in the setup, I get the same numbers everytime on programstart.
But I want random-numbers. ;-)
any tips?

best regards and thank you in advance!


Code:
 randomSeed(analogRead(0));

  Serial.println("random(1000)...");
  uint8_t i, j;
  for (i=0; i<10; i++) {
    j=random(1000);
    Serial.print(j);  Serial.print(" ");
  }

how to get random numbers? Random10

tested in SR0 (and some other releases) on linux64
Attachments
how to get random numbers? Attachmentrandom_01.zip
You don't have permission to download attachments.
(4 Kb) Downloaded 1 times

2how to get random numbers? Empty Re: how to get random numbers? Sun May 14, 2023 10:41 pm

Fizik_S

Fizik_S

KarstenLehmann wrote:Hello,
when I use the following lines in the setup, I get the same numbers everytime on programstart.
But I want random-numbers. ;-)
any tips?

best regards and thank you in advance!


Finalize the scheme as shown in the figure. Before starting the sketch, turn the potentiometer knob to an arbitrary position. This is the easiest way.
how to get random numbers? Random10

KarstenLehmann likes this post

3how to get random numbers? Empty Re: how to get random numbers? Mon May 15, 2023 2:03 pm

Defran

Defran

The software typically produces pseudo_random data. In the case of Arduino you can extended the random values with the "seed" instruction making reference to some analog pin (A0 for instance) where you will connect the simulide generator at very low frequence in sinus. This will produce irregular values that will increase the randomness.

Look at the examples in this regard in the section "Projets Made in Simulide".

Good luck.

KarstenLehmann likes this post

4how to get random numbers? Empty Re: how to get random numbers? Thu May 25, 2023 8:55 am

OKF



KarstenLehmann wrote:Hello,
when I use the following lines in the setup, I get the same numbers everytime on programstart.
But I want random-numbers. ;-)
any tips?

best regards and thank you in advance!
Code:
#include <avr/eeprom.h>
EEMEM uint8_t ee_seed;
  randomSeed(eeprom_read_byte(&ee_seed));
  eeprom_write_byte(&ee_seed, eeprom_read_byte(&ee_seed) + 1);

KarstenLehmann likes this post

5how to get random numbers? Empty Re: how to get random numbers? Thu May 25, 2023 9:58 pm

Defran

Defran

With a External Analog Variable Value in A4:

how to get random numbers? 2023-030
how to get random numbers? 2023-031
how to get random numbers? 2023-032
Attachments
how to get random numbers? AttachmentRANDOM_PWM_LED.zip
You don't have permission to download attachments.
(6 Kb) Downloaded 2 times

KarstenLehmann likes this post

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum